Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Passing Hash to Subroutine

by fx (Pilgrim)
on Dec 28, 2003 at 20:37 UTC ( [id://317332] : note . print w/replies, xml ) Need Help??


in reply to Passing Hash to Subroutine

If I pass a reference to a hash into a sub, I keep working with the reference:

some_sub(\%some_hash); sub some_sub { my $hash_ref = $_[0]; ## Now communicate with hash using: ## $hash_ref->{'SOME_KEY'} returns the value for SOME_KEY ## or ## $hash_ref->{'OTHER_KEY'} = "foo" will set a key to a value ## etc. ## Or the slightly more exciting: ## foreach $key (keys %{$hash_ref}) { ## do_something_with $hash_ref->{$key} }