Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Loop through hash structure

by nvivek (Vicar)
on Sep 07, 2010 at 05:28 UTC ( #859110=note: print w/ replies, xml ) Need Help??


in reply to Loop through hash structure

You can use the following code for getting the values of hash.

for my $record ( $hash{'Application'}) { print "Environment:".$record->{'Environment'}[0]->{'Name'} ."\n"; print "Region:".$record->{'Environment'}[0]->{'Region'}[0]->{'Name'}." +\n"; print "Idrive:".$record->{'Environment'}[0]->{'Region'}[0]->{'Idrive'} +."\n"; print "LPad:".$record->{'Environment'}[0]->{'Region'}[0]->{'Zdrive'}." +\n"; }

For your reference, I have used the index as 0.You can find the length of the array in the hash and you can loop through the array length.


Comment on Re: Loop through hash structure
Download Code
Re^2: Loop through hash structure
by PerlScholar (Acolyte) on Sep 07, 2010 at 11:43 UTC
    Hi Nvivek,

    This looks like what I need, however I would like to loop through all the indexes not just 0 or 1 is there a way to do that? Taking out the index number gives the error. Thanks!

    Pseudo-hashes are deprecated at Z:/My Documents/Workspace/Script.pl line 12.
    Argument "\x{51}\x{41}" isn't numeric in hash element at Z:/My Documents/Workspace/Script.pl line 12.
    Bad index while coercing array into hash at Z:/My Documents/Workspace/Script.pl line 12.

        Hi Corion, had a look at those 2 documents and tried a few things but still no breakthrough. I can only seem to access the array values when I include the index as above. Is there any simple way of looping through or am I using a poor structure or something? Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://859110]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-07-23 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (130 votes), past polls