in reply to Modifying a hash in a subroutine?
The code simplifies to:
modifyHash(\%my_hash); sub modifyHash { my $hash_ref = shift; # Do something to the hash ${$hash_ref}{'test'} = 1; #$hash_ref->{'test'} = 1; #alternative }
basically, use {$hash_ref} wherever my_hash would have appeared:
%my_hash -> %{$hash_ref} keys(%my_hash) -> keys(%{$hash_ref}) %my_hash = (); -> %{$hash_ref} = () $my_hash{$key} -> ${$hash_ref}{$key}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Modifying a hash in a subroutine?
by C_T (Scribe) on Aug 20, 2004 at 16:02 UTC |