Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: What is happening ?

by Marshall (Prior)
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


Comment on Re: What is happening ?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-12-28 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls