RSSの出力をperlから行ってみた。
とりあえずCPANからXML::RSSモジュールをインストール
perl -MCPAN -e shell cpan> install XML::RSS
これをやると、XML::RSS::Expatでコンパイルエラーが出る。
ということで、Expat XML ParserというCのライブラリをインストール(./configure ; make ; make install)
Expartは下記のURLからダウンロード。
http://www.libexpat.org/
http://sourceforge.net/projects/expat/
とりあえず、サンプルとして、簡単なRSSを出力するスクリプトを書いてみた。
CGIなので、print "Content-type: application/xml;\n\n";という一文が必要。
#!/usr/bin/perl use XML::RSS; my $rss = new XML::RSS(version => '1.0'); $rss->channel( title => "testtitle", link => "http://test.com/", description => "test description", ); $rss->add_item( title => "item title", link => "http://test.com/", description => "item1", ); print "Content-type: application/xml;\n\n"; #セットしたXML情報を出力 print $rss->as_string;
とりあえずうまくいったので、あとは適当に改良するだけで色々出来そう。
出力はUTF8なので、もしtitleやdescriptionに日本語を含める場合はUTF8エンコードをしないといけない。
perl5.8ならば標準でそれが出来るみたい。
英数字のみであれば、sjisもutf8もコード体系は同じなので問題なし。