Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: problem using foreach and each with hash ref

by sanku (Beadle)
on Aug 21, 2009 at 12:34 UTC ( #790349=note: print w/replies, xml ) Need Help??

in reply to problem using foreach and each with hash ref

hi, I think it's not that much easy to both key and value pair for hash but you can get either key or value. In my code i used the keys indexes to get the values of hash reference.
use strict; use warnings; use Data::Dumper; my $hash_ref={1002=>[1,2,3,4,5],1001=>[6,7,8,9,10],3=>[2]}; my ($hashref,$array_ref,@array,); foreach $hashref( keys %$hash_ref){ $array_ref=$$hash_ref{$hashref}; @array=@$array_ref; print "Key = ".$hashref."\tValue = "; foreach (@array){ print "$_ \t"; } print "\n"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://790349]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2017-06-24 02:02 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (556 votes). Check out past polls.