Syrkres has asked for the wisdom of the Perl Monks concerning the following question:
Seem to be having an issue in trying to walk hash of hashs. It seemed to be working but now not working. I uninstalled perl and installed again (activestate 5.18 64bit)
Just updated to perl 5.20.2.2002 64bit - still same result.
#!perl use XML::Simple; use Data::Dumper; my $xmlSimple = new XML::Simple(KeepRoot => 1); my $professionsXML = $xmlSimple->XMLin("data/misc/test.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}) { print qq(1: $key\n); foreach my $key2 (keys %{$professionsXML{$key}}) { print qq(2: $key2\n); foreach my $key3 (keys %{$professionsXML{$key}{$key2}}) { print qq(3: $key3\n); foreach my $key4 (keys %{$professionsXML{$key}{$key2}{$key +3}}) { print qq(4: $key4\n); } } } } exit(0);
XML Source
<profs> <name>prof</name> <profcats> <name>cat</name> <profcatgroups> <name>group</name> <profcatgroup> <name>prof1</name> </profcatgroup> </profcatgroups> </profcats> </profs>
Output
C:\Utils\Apache\Apache-httpd-2.2\cgi-bin>perl generate03.pl $VAR1 = { 'profs' => { 'profcats' => { 'profcatgroups' => { 'name' => 'group +', 'profcatgroup' = +> { + 'name' => 'prof1' +} }, 'name' => 'cat' }, 'name' => 'prof' } }; 0.1: 0.2: 1: profs 2: profcats C:\Utils\Apache\Apache-httpd-2.2\cgi-bin>
As you can see from output, it I can't seem to manually walk tree, and in using loops to walk try it seems to get hungup after profcats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Walking Hash of hash issue?
by Corion (Patriarch) on Oct 23, 2015 at 16:51 UTC | |
|
Re: Walking Hash of hash issue?
by Preceptor (Deacon) on Oct 23, 2015 at 16:44 UTC | |
|
Re: Walking Hash of hash issue?
by stevieb (Canon) on Oct 23, 2015 at 16:54 UTC | |
by Syrkres (Sexton) on Oct 27, 2015 at 13:12 UTC |