Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: What is happening ?

by Marshall (Abbot)
on Aug 19, 2009 at 09:37 UTC ( #789750=note: print w/replies, xml ) Need Help??

in reply to problem using foreach and each with hash ref

Not sure what you want:
There are lots of ways to sort this stuff once we agree on the data to be output. Since $rHol is a reference, you need the -> operator to deference the key, normal hash would be just $Hol{$key}, but you need $rHoL->{$key}. Then you need {} around that whole thing to tell the @ operator what to operate upon.

#!/usr/bin/perl -w use strict; my $hash_ref= {1002=>[1,2,3,4,5], 1001=>[6,7,8,9,10], 3 =>[2]}; print_HoL($hash_ref); sub print_HoL { my $rHoL = shift; foreach my $key (keys %$rHoL) { print "$key: @{$rHoL->{$key}}\n"; } } __END__ Prints: 1001: 6 7 8 9 10 1002: 1 2 3 4 5 3: 2

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-04-22 20:55 GMT
Find Nodes?
    Voting Booth?