This will print something likeuse Data::Dumper; my $content = join '', <DATA>; my $response = XMLin($content); print Dumper($response);
and shows that starting from $response (which is a reference to a hash), you need to step down to the value of the offer key.$VAR1 = { 'offer' => { '6' => { 'zip' => '48120', 'transit' => '1', 'smoking' => {}, 'phone_public' => '1', 'state' => 'MI' }, '60046' => { 'zip' => '80236', 'transit' => '1', 'smoking' => {}, 'phone_public' => '1', 'state' => 'CO' }, '7' => { 'zip' => '43240', 'transit' => '1', 'smoking' => {}, 'phone_public' => '1', 'state' => 'MI' } } };
There, you'll find another reference to a hash. This one contains one entry per id, so all you need to do is loop over these keys and then step down to the zip element of the sub-hash:
This will print the zip codes you're interested in:my $response = XMLin($content); for my $id (keys %{$response->{offer}}) { print $response->{offer}->{$id}->{zip}, "\n"; }
48120 80236 43240
In reply to Re: XML::Simple help -- please
by saintmike
in thread XML::Simple help -- please
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |