Translate

2008年7月31日木曜日

URIモジュール

URLを触る時は、URI(perlモジュール名)が超便利だと思う。

と、言うわけで触ってみた。
-分解編-
use strict;
use warnings;
use URI;

print "URI_VERSION: ", URI->VERSION, "\n\n";
my $uri = URI->new("http://www.hoge.com/path1/path2/?q1=abc&q2=cde");

print "URI: ", $uri, "\n";
print "scheme: ", $uri->scheme, "\n";
print "host: ", $uri->host, "\n";
print "path: ", $uri->path, "\n";
print "query: ", $uri->query, "\n\n";

$uri = URI->new("http://www.hoge.com/path1/path2/index.html#hoge");
print "URI: ", $uri, "\n";
print "fragment: ", $uri->fragment, "\n";

実行結果



-結合編-
use strict;
use warnings;
use URI;

my $uri = URI->new("http://www.hoge.com/path1/path2/");
$uri->query_form(q1 => 'abc', q2 => 'def');

print "URI: ", $uri, "\n";


実行結果
-------------------------------------------------------------
URI: http://www.hoge.com/path1/path2/?q1=abc&q2=def
-------------------------------------------------------------

0 件のコメント: