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.In reply to Nested Hash/Arrays Access by Wookimonsta
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |