Wookimonsta has asked for the wisdom of the Perl Monks concerning the following question:
Alright, to begin, I am pretty much a Perl newbie, I only just started learning the language for a project with the help of the "Perl Cookbook" by O'Reilly that someone loaned me. This is my first post, so be kind.
My Problem is that I have created a complex (at least it seems complex to me in Perl as I am more used to C) data structure.
Basically the data structure looks like this:
I have a hash table where I store the name of a server and a reference to another hash as a pair.
Within this second Hash, I store a Process ID and a reference to another Hash as a pair.
Within this third Hash, I store a FD (a column from the LSOF file) and a reference to an array as a pair.
In this array I store all the data from an LSOF line.
Now I have checked this Data structure, and everything seems to be saved properly and nothing overwritten etc.
17 foreach $server (keys %servers) #returns individual servers 18 { 19 print "$server\n"; 20 foreach $process (keys %{$servers{$server}}) #returns indi +vidual processes on a server 21 { 22 print "$process\n"; 23 foreach $processPart (keys %{$servers{$server{$pro +cess}}}) # returns part of a process 24 { 25 print "$processPart\n"; 26 } 27 } 28 }
now, this works up until the second level. It prints out all of the $server and $process values but does not print $processPart.
my problem I think is the line:
foreach $processPart (keys %{$servers{$server{$process}}})what im trying to do here is return the keys of the the third hash (eventually I want to return the actual Array reference and later the actual data in the array, but this shouldn't be a problem once I get the past this step (I think).
Basically, how do I keep accessing deeper and deeper Nested Hashes/Arrays in a foreach in this manner?I was also wondering if there was a better way rather than just nested foreach statements. Like I said I am new to Perl so forgive me if there is a really easy answer to this.
Looking forward to help as this has been bugging me for three days.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Nested Hash/Arrays Access
by kennethk (Abbot) on Jul 20, 2009 at 14:52 UTC | |
by AnomalousMonk (Archbishop) on Jul 20, 2009 at 16:20 UTC | |
by Wookimonsta (Initiate) on Jul 21, 2009 at 10:13 UTC | |
|
Re: Nested Hash/Arrays Access
by Unforgiven (Hermit) on Jul 20, 2009 at 14:50 UTC | |
|
Re: Nested Hash/Arrays Access
by johngg (Canon) on Jul 20, 2009 at 22:54 UTC | |
by Wookimonsta (Initiate) on Jul 21, 2009 at 10:16 UTC | |
|
Re: Nested Hash/Arrays Access
by ww (Archbishop) on Jul 20, 2009 at 22:04 UTC |