The error message is exactly what the problem is--you are trying to use the reference in $ref->{ICD_Description} as an array, when it's actually a hash. You can't use your foreach loop to traverse through the data in the way you are trying.

In other words, $ref is a hashref, and $ref->{ICD_Description} is also a hashref, but you're trying to use it like it's an array ref. The output from Dumper is the key to seeing what kind of data are in the variable. If a section starts with a {, it is a hashref; if it starts with a [ it is an array ref. It also looks like StructureType points to an array ref, which then has a list of hashrefs.

You should be able to access the array of StructureTypes with something similar to the following (untested):

foreach my $structure_type (@{$ref{ICD_Description}{MsgData}{MsgDataRe +gion}{Msg_Data}{Array}{StructureType}}) { print "$structure_type{DataLine}{DataField}\n"; }

In reply to Re: Parsing deep XML by lostjimmy
in thread Parsing deep XML by FlanOSU

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.