Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: deferencing an hash in a subroutine

by BioLion (Curate)
on Aug 20, 2010 at 15:09 UTC ( #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...


Comment on Re: deferencing an hash in a subroutine
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2015-08-01 01:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls