Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2016-10-23 21:38 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (302 votes). Check out past polls.