Hello everyone! I have a quick question about using XML::Simple to parse some data from the DOT to get traffic reports and such. I have an xml file that lookst like this:
$VAR1 = { 'incident-report' => [ { 'incident' => { 'GDOT-INC-260089' => { 'location' => { 'link' => { 'direction' => 'South', 'hwy' => '2', 'content' => 'Southbound I-75 at DELK ROAD', 'name' => 'I-75', 'id' => '2078', 'mile-post' => '261.66' }, 'coord' => { 'y' => '435177', 'unit' => 'meters', 'x' => '670359', 'datum' => 'NAD83', 'projection' => 'GA State Plane West' }, 'county' => { 'content' => 'Cobb', 'id' => '67' }, 'type' => { 'content' => 'Freeway', 'id' => '1' }, 'description' => 'Southbound I-75 at Delk Road' }, 'status' => 'active', 'description' => 'Medium impact, 1 tractor-trailer, Cobb Co.', 'lanes' => '2 Right Lanes', 'level' => '3', 'type' => { 'content' => 'Accident', 'id' => '1' }, 'cleanup' => { 'timestamp' => '2003-06-19 17:20:00 EDT', 'content' => ' 5:20 PM Today' }, 'impact' => { 'content' => 'Medium', 'id' => '2' } },
and basically I am having trouble forcing the incident into an array so I can call it like this:
print $ref->{incident}->[0]->{location}->{county}->{content} . "\n";
It gives me the error about not being a valid array. Can anyone suggest something that might work to get that 'GDOT-INC-260089' part into an array so that I can loop through them? I want to share the code for this when I get it finished. Maybe someone in Georgia will be able to use it ;-)

2003-06-21 edit ybiC: two-space indents, quasi-vertical alignment of comma-arrows for legibility


In reply to XML::Simple parsing :-( by st4k

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.