If you have a data structure and don't know what's in there, use Data::Dumper to dump it:
use Data::Dumper; my $content = join '', <DATA>; my $response = XMLin($content); print Dumper($response);
This will print something like
$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' } } };
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.

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:

my $response = XMLin($content); for my $id (keys %{$response->{offer}}) { print $response->{offer}->{$id}->{zip}, "\n"; }
This will print the zip codes you're interested in:
48120 80236 43240

In reply to Re: XML::Simple help -- please by saintmike
in thread XML::Simple help -- please by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.