Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: deferencing an hash in a subroutine

by BioLion (Curate)
on Aug 20, 2010 at 15:09 UTC ( [id://856297]=note: print w/replies, xml ) Need Help??


in reply to deferencing an hash in a subroutine

In neither of your examples are you using a reference. Try something more like:

use strict; use warnings; my %hash = (foo => 1, bar => 2,); # pass reference to subroutine test(\%hash); ########## SUB ######### sub test{ my $reference = shift; # reference is passed in @_ print "REF: $reference\n"; print "KEY: " . $_ . " VAL: " . $reference->{$_} . "\n" for (keys +%$reference); }

Check out perlref and References quick reference for more info on references and dereferencing! HTH!

Just a something something...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 05:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found