memo.xight.org

Home > Changelogメモ > Perl > 5ページ目 (全6ページ)
ChangeLog 最新ページ / カテゴリ最新ページ / 前ページ 1 2 3 4 5 6 次ページ / 5ページ目 (全6ページ)
2008-12 / 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

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(@_)}

カテゴリ: [chalow][Perl]

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/

カテゴリ: [Perl]

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/

カテゴリ: [Perl]

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

カテゴリ: [Perl]

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

カテゴリ: [Perl]

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

カテゴリ: [Perl][PHP][SOAP]

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

カテゴリ: [Perl]

2004-08-13 Fri

結城浩のPerlクイズ

- Reference
  SOFTBANK BOOKS - 結城浩のPerlクイズ
  http://books-support.softbank.co.jp/pq/

カテゴリ: [Perl]

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

カテゴリ: [Perl]

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

カテゴリ: [Perl]

2004-08-02 Mon

Python,Perl,Rubyを使ったXMLプログラミング (改訂版)

- Reference
  Python,Perl,Rubyを使ったXMLプログラミング (改訂版)
  http://www.yoshidam.net/PythonPerlRuby.html

カテゴリ: [Perl][Python][Ruby][XML]

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

カテゴリ: [Perl][Solaris]

2004-08-02 Mon

CPAN.pm のアップデート

- 以下を実行

# perl -MCPAN -e shell
cpan> install Bundle::CPAN
cpan> reload cpan

カテゴリ: [Perl]

2004-07-31 Sat

多次元連想配列の走査

- Source

foreach $firstkey (keys %HOGE){
	print "<b>$firstkey:</b><br>";
	foreach $secondkey (keys %{$HOGE{$firstkey}}){
		print "$secondkey = $HOGE{$firstkey}{$secondkey}<br>";
	}
	print "<br>\n";
}

- Reference
  お気楽極楽スクリプト - スクリプト制作メモ - Perlの変数について
  http://www.bayashi.net/st/pdmemo/variable.html

カテゴリ: [Perl]

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

カテゴリ: [Perl][PHP]

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

カテゴリ: [Perl][正規表現]

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

カテゴリ: [Perl]

2004-06-18 Fri

Perl の真偽値

- 一覧

偽になるもの
空の文字列 "" ''
文字の0 "0" '0'
数値の0 0 0.0 3-3
空のリスト ()
未定義値
それ以外は真.

- 注意
  "0.0" は 真 (true)
  length() を用いて長さを得れば,文字列 '0' でも真となる.

- Reference
perlsyn

カテゴリ: [Perl]
内部リンク: [2004-12-29-12]

2004-06-11 Fri

連想配列の走査

- キーでソート

foreach $key (sort(keys %hash)) {
	print "$key => $hash{$key}\n";
}


- キーでソート (逆順)
foreach $key (sort {$b cmp $a} keys %hash){
	print "$key => $hash{$key}\n";
}


- 値 (数値) でソート (昇順)
foreach $key (sort { $hash{$a} <=> $hash{$b} } keys %hash) {
	print "$key => $hash{$key}\n";
};


- 値 (文字列) でソート (昇順)
foreach $key (sort { $hash{$a} cmp $hash{$b} } keys %hash) {
	print "$key => $hash{$key}\n";
};


- 値 (数値) でソート (降順)
foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
	print "$key => $hash{$key}\n";
};



- 値 (文字列) でソート (降順)
foreach $key (sort { $hash{$b} cmp $hash{$a} } keys %hash) {
	print "$key => $hash{$key}\n";
};

カテゴリ: [Perl]
2008-12 / 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
最終更新時間: 2008-12-02 10:52

Color Reference

ChangeLogを検索
携帯電話からアクセス!

カテゴリ

最近の話題

リンク

過去ログ

Google

QR Code

Since
2002-11-28
Update
2008-12-02 10:52
Copyright © 2005 xight.org All Rights Reserved.