WEB API XML サンプル (LiveDoor Weather)

# WEB API XML サンプル
#!c:/Perl/bin/perl.exe

use encoding 'UTF-8', STDOUT => 'cp932';

use HTTP::Request;
use LWP::UserAgent;

use LWP::Simple;

use XML::Simple;

$result = LWP::Simple::get("http://weather.livedoor.com/forecast/webservice/rest/v1?city=70&day=today");


$xml = new XML::Simple();
$sample = $xml->xml_in($result);

print "\n\n";

## スカラーテスト

$result = $sample->{title};
print $result."\n\n";

$result = $sample->{description};
print $result."\n\n";


## 配列アクセス


foreach my $loc (@{$sample->{pinpoint}->{location}}) {

print $loc->{title}." ".$loc->{link}."\n";

}