2004-10-26 Tue
chalowの CPAN 検索プラグイン
- CPAN 検索プラグイン
### CPAN Moduleの検索リンク # usage: {{cpan_search('Keyword','mode')}} # mode : all - Search in All # dist - Search in Distributions # module - Search in Modules (default) # author - Search in Author sub cpan_search { my ($word,$mode) = @_; my $prefix = q(http://search.cpan.org/search); if ($mode ne 'all' && $mode ne 'dist' && $mode ne 'author' && $mode ne 'module'){ $mode = q(all); } return qq(<a href="$prefix?m=$mode&q=$word" title="CPAN Search - $word">$word</a>); } sub cpan{cpan_search(@_)}
2004-10-26 Tue
Template::Extract + XML::RSS でRSS 生成
- 必要なモジュール
Template::Extract
XML::RSS
- Reference
NDO::Weblog - 2004-01-11
http://naoya.dyndns.org/~naoya/mt/archives/000833.html
Template::Extract
XML::RSS
- via
cl.pocari.org - 2004-05-11
http://cl.pocari.org/2004-05.php#2004-05-11-1
2004-10-06 Wed
WWW::Mechanize
- Summary
LWP::UserAgentのサブクラス
- https://で始まるSSL使用サイトに接続するには
IO::Socket::SSLとCrypt::SSLeay,またはNet::SSLeayモジュールが必要.
- Proxyを使用するには
$self->proxy(['http', 'ftp'], 'http://proxy.example.com:8000/');
または,環境変数HTTP_PROXY,HTTPS_PROXYを設定しておけば,コンストラクタ内で
$self->env_proxy();
が呼び出されるのでOK.
- フォームフィールドの取得
全てのフォームフィールドについて,フィールド名,タイプ,値を書き出すスクリプト
use WWW::Mechanize; my $url = "http://www.example.com/form.html"; my $mech = WWW::Mechanize->new( cookie_jar => undef ); my $response = $mech->get( $url ); foreach my $form ($mech->forms) { foreach my $input ($form->inputs) { printf("%s (%s) ... %s\n", $input->name, $input->type, $input->value); } }
- "input 'fieldname' is readonly" のエラー
hiddenフィールドの値を変更しようとした場合のWarning
hiddenフィールドの値を変更するならWarningをOffにしてから.
{ local $^W = 0; $agent->field( name => $value ); }
- Reference
WWW-Mechanize
Walrus, Digit. - Perlモジュール/WWW::Mechanize
http://digit.que.ne.jp/work/?Perl%A5%E2%A5%B8%A5%E5%A1%BC%A5%EB%2FWWW%3A%3AMechanize
Perldoc.jp - Modules - WWW-Mechanize
http://perldoc.jp/docs/modules/WWW-Mechanize-1.02/
2004-09-27 Mon
Perl で MSN Messenger
- MSN.pm
MSN MessengerをPerlから操作するためのモジュール
Bot-Depot - MSN Protocol modules - MSN.pm
http://www.bot-depot.com/forums/?showforum=12
#!/usr/bin/perl use MSN; use Jcode; my $msn = MSN->new(Handle => 'hoge@hotmail.com', Password => 'hogepass'); $msn->set_handler(Message => \&on_message); $msn->connect(); while(1) { $msn->do_one_loop(); } sub on_message { my ($self, $email, $name, $msg) = @_; my $utf8_name = Jcode->new($name, 'utf8')->euc; my $str = Jcode->new($msg, 'utf8')->euc; # $str を処理... my $utf8_str = Jcode->new($str, 'euc')->utf8; $self->sendmsg($utf8_str); }
- Net::Msmgr
Net-Msmgr
http://search.cpan.org/~slstat/Net-Msmgr/
- Install
# perl -MCPAN -e 'install Net::Msmgr'
- Net::MSN
Net-MSN
http://search.cpan.org/~djr/Net-MSN/
- Install
# perl -MCPAN -e 'install Hash::Merge'
# perl -MCPAN -e 'install Net::MSN'
- Reference
Bot-Depot
http://www.bot-depot.com/
cubic9.com - Linux/Perl/MSN.pm
http://cubic9.com/Devel/Perl/MSN.pm%20%28Bot-Depot%20realesed%29/
2004-09-10 Fri
Image::Magickの使用法
- サムネイルを生成
Transformは,同じ比率で画像を縮小拡大する
#!/usr/bin/perl use Image::Magick; # 新しい幅だけ指定する $newwidth = 120; $i = Image::Magick->new; $i->Read('input.gif'); # Transformは同じ比率で画像を縮小拡大する $i = $i->Transform(geometry=>$newwidth); print "Content-type: image/gif\n\n"; binmode(STDOUT); $i->Write("gif:-"); exit;
- 幅と高さを指定して,GIFファイルをJPEGに変換する
Scaleは,縦横のピクセルを与え縮小拡大する
#!/usr/bin/perl use Image::Magick; $newwidth = 160; $newheight = 160; $i = Image::Magick->new; $i->Read('input.gif'); # Scaleは縦横のピクセルを与え縮小拡大する $i->Scale(geometry=>geometry,width=>$newwidth,height=>$newheight); print "Content-type: image/gif\n\n"; binmode(STDOUT); # JPEGで出力 $i->Write("jpeg:-"); exit;
- 枠の追加
| width | 枠の幅 |
| height | 枠の高さ |
| inner | 内枠の幅 |
| outer | 外枠の幅 |
#!/usr/bin/perl use Image::Magick; $infile = "input.jpg"; $i = Image::Magick->new; $i->Read($infile); # 枠の幅がwidth,枠の高さがheight,内枠の幅がinner,外枠の幅がouter $i->Frame(geometry=>geometry,width=>6,height=>6,inner=>2,outer=>2,color=>'#50FF50'); print "Content-type: image/gif\n\n"; binmode(STDOUT); $i->Write("jpeg:-"); exit;
- 画像の回転
| degrees | 回転の角度 (-360〜360) |
| crop | 1を指定すると元の画像の大きさを変えない |
| sharpen | 1を指定すると,シャープフィルタを付加する |
#!/usr/bin/perl use Image::Magick; $infile = "input.jpg"; $i = Image::Magick->new; $i->Read($infile); $i->Set(bordercolor=>'#FFFFFF'); $i->Rotate(degrees=>-30,crop=>0,sharpen=>1); $i->Trim(); print "Content-type: image/gif\n\n"; binmode(STDOUT); $i->Write("jpeg:-"); exit;
- Reference
ImageMagick.org
http://www.imagemagick.org/
ImageMagic(PerlMagic)
http://www.tryhp.net/homeserver16.htm
2004-09-10 Fri
モジュールの一括バージョンアップ & インストール
- 古くなっているモジュールの一覧
$ perl -MCPAN -e 'CPAN::Shell->r'
- 古くなっているモジュールを一括してバージョンアップ
# perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
- 他の環境にインストールされているモジュールを一括してインストール
例えばperl本体をバージョンアップしたときはこんな感じで。
# perl-5.6 -MCPAN -e autobundle
# perl-5.8 -MCPAN -e 'install Bundle::Snapshot_2004_06_16_00'
- Reference
はてなダイアリー - (ひ)のメモ - 2004-06-18
http://d.hatena.ne.jp/hirose31/20040618#1087530672
- via
cl.pocari.org - 2004-09-06
http://cl.pocari.org/2004-09.php#2004-09-06-13
2004-09-07 Tue
SOAPの簡単な使用例
- Reference
河馬屋二千年堂's Page - Perlの小技 - SOAP::Liteモジュール
http://homepage3.nifty.com/hippo2000/perltips/SOAP/Lite.htm
[PHP-users 9699] SOAPによる実装
http://ns1.php.gr.jp/pipermail/php-users/2002-September/009705.html
[PHP-users 9741] Re: SOAPによる実装
http://ns1.php.gr.jp/pipermail/php-users/2002-September/009747.html
2004-09-01 Wed
Pdoc
- Summary
Perlのドキュメント(POD)をJavadoc風のHTMLに変換
- Reference
SourceForge - Pdoc
http://pdoc.sourceforge.net/
- via
textfile.org - 2004-08-30
http://www.hyuki.com/tf/20040830220311.html
2004-08-13 Fri
結城浩のPerlクイズ
- Reference
SOFTBANK BOOKS - 結城浩のPerlクイズ
http://books-support.softbank.co.jp/pq/
2004-08-12 Thu
Perlでithreadを使用する
- Summary
Perl5.8から採用されたithreadというスレッドモデルを使用するためのドキュメント
- Reference
KaWaZ.jp - PukiWiki - Perlでマルチスレッド
http://www.kawaz.jp/pukiwiki/?Perl%A4%C7%A5%DE%A5%EB%A5%C1%A5%B9%A5%EC%A5%C3%A5%C9
2004-08-06 Fri
XML::Parser
- 使用法
use XML::Parser; my $parser = new XML::Parser(Style=>'Stream'); $parser->parsefile($ARGV[0]); sub StartDocument { print qq(StartDocument\n); } sub EndDocument { print qq(EndDocument\n); } sub StartTag { print qq(StartTag $_[1]\n); } sub EndTag { print qq(EndTag $_[1]\n); } sub Text { print qq($_\n); }
- 注意
Textはテキストの開始と終了で呼び出される.
StartTextとEndTextサブルーチンに分かれていればいいのに.
- Reference
XML-Parserモジュール (日本語チョウ訳)
http://member.nifty.ne.jp/hippo2000/perltips/xml/parser.htm
2004-08-02 Mon
Python,Perl,Rubyを使ったXMLプログラミング (改訂版)
- Reference
Python,Perl,Rubyを使ったXMLプログラミング (改訂版)
http://www.yoshidam.net/PythonPerlRuby.html
2004-08-02 Mon
Perl5.8.5のインストール
- 以下を実行
$ tar -zxvf perl-5.8.4.tar.gz
$ cd perl-5.8.4
$ ./Configure -Dcc=gcc -Doptimize=-O2 -Dusethreads -ders
$ make
$ env LC_ALL=C make test
# make install
- Reference
CPAN/src
http://www.cpan.org/src/README.html
Solarisインストールメモ - perl5.8.4
http://apollo.u-gakugei.ac.jp/~sunaoka/solaris/install/install.cgi#18
2004-08-02 Mon
CPAN.pm のアップデート
- 以下を実行
# perl -MCPAN -e shell
cpan> install Bundle::CPAN
cpan> reload cpan
2004-07-31 Sat
多次元連想配列の走査
2004-07-31 Sat
多次元連想配列
- Perl
%PREF = ( 'kyoto' => { 'NAME' => '京都', 'JINKOU' => '200万', 'MEISAN' => '豆腐', }, 'osaka' => { 'NAME' => '大阪', 'JINKOU' => '500万', 'MEISAN' => 'たこやき', }, );
$PREF{'kyoto'}{'NAME'} = 京都
- PHP
$PREF = array( "kyoto" => array( "NAME" => "京都", "JINKOU" => "200万", "MEISAN" => "豆腐", ), "osaka" => array( "NAME" => "大阪", "JINKOU" => "500万", "MEISAN" => "たこやき", ), );
$PREF["kyoto"]["NAME"] = 京都
- Reference
PHPマニュアル - 配列
http://www.php.net/manual/ja/language.types.array.php
- via
PHP-users ML - 13954
http://ns1.php.gr.jp/pipermail/php-users/2003-March/014486.html
PHP-users ML - 13956
http://ns1.php.gr.jp/pipermail/php-users/2003-March/014488.html
2004-07-26 Mon
Unicode の Property を利用した正規表現
- \p{Han}
漢字にマッチ
- \p{Hiragana}
ひらがなにマッチ
- \p{Katakana}
カタカナにマッチ
- Reference
perl5.8のUnicodeサポート
http://www.lr.pi.titech.ac.jp/~abekawa/perl/perl_unicode.html
module.jp - 日本語に絡むUnicodeブロックとスクリプト (正規表現)
http://module.jp/blog/regex_unicode_prop.html
Script と実際のコードポイントとの対応表
http://www.unicode.org/Public/UNIDATA/Scripts.txt
2004-07-20 Tue
PAR - Perl のスクリプトから実行形式のファイルを生成
- Summary
Perl のスクリプトから実行形式のファイルを生成することができる.([2004-10-26] 追記: Windowsに限らない)
PARファイル(zip)として必要なスクリプト,モジュールをパッケージ化できる.
JavaのJARファイルのような使い方ができる.
HTTPサーバ上にあるPARファイルをリモートから取得する機能があり,Java Web Startに近い使い方もできるらしい.
- Reference
PAR Homepage
http://par.perl.org/
Open Alexandria - PAR
http://www.openalexandria.com/item_306.html
いやな日記 - 2004-07-16
http://namazu.org/~satoru/diary/20040716.html#p01
Naney's Web Site - nDiki - PAR
http://www.naney.org/diki/dk/PAR.html
- via
たつをのChangeLog - 2004-07-16
http://chalow.net/2004-07-16.html#2004-07-16-3
2004-06-18 Fri
2004-06-11 Fri
連想配列の走査
- キーでソート
- キーでソート (逆順)
- 値 (数値) でソート (昇順)
- 値 (文字列) でソート (昇順)
- 値 (数値) でソート (降順)
- 値 (文字列) でソート (降順)