Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: What is happening ?

by Marshall (Canon)
on Aug 19, 2009 at 09:37 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-18 18:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found