use warnings; and in this case specifically, use strict; will point you to your errors. Correct those and you'll be much further along.

You're not accessing the elements of the hash reference correctly (perl thinks you're trying to access a hash, not a reference to one). Use the -> dereference operator between the reference and the first key to distinguish it as a ref, eg: %{$professionsXML->{$key}}.

Also, there are values in that structure that are not hashrefs, so you need to explicitly check for this. Here's (a messy) working example to show you what I mean by my statements. I most likely wouldn't have written it like this, but I wanted to point out where the mistakes are within the code structure you provided

use warnings; use strict; use XML::Simple; use Data::Dumper; my $xmlSimple = new XML::Simple(KeepRoot => 1); my $professionsXML = $xmlSimple->XMLin("in.xml"); print Dumper($professionsXML); print qq(0.1: $professionsXML->{'profs'}{'name'}\n); print qq(0.2: $professionsXML->{'profs'}{'profcats'}{'name'}\n); foreach my $key (keys %{$professionsXML}) { next if ref $professionsXML->{$key} ne 'HASH'; print qq(1: $key\n); foreach my $key2 (keys %{$professionsXML->{$key}}) { next if ref $professionsXML->{$key}{$key2} ne 'HASH'; print qq(2: $key2\n); foreach my $key3 (keys %{$professionsXML->{$key}{$key2}}) { next if ref $professionsXML->{$key}{$key2}{$key3} ne 'HASH +'; print qq(3: $key3\n); foreach my $key4 (keys %{$professionsXML->{$key}{$key2}{$k +ey3}}) { print qq(4: $key4\n); } } } } exit(0);

In reply to Re: Walking Hash of hash issue? by stevieb
in thread Walking Hash of hash issue? by Syrkres

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.