in reply to Walking Hash of hash issue?

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);

Replies are listed 'Best First'.
Re^2: Walking Hash of hash issue?
by Syrkres (Sexton) on Oct 27, 2015 at 13:12 UTC
    Thanks all for the comments/help. I have been very slack in using perl in the last 4-5 years, so when I saw the removal of the hash pointers I thought that was the new way to do it. I thought I tried swapping back, but must have had other errors at the time. I will take a look at the other packages. Again Greatly thanks for help!