in reply to dbmopen mistake?
Here are 2 options to correct this:my %hash; populate_hash(%hash); sub populate_hash{ my %h = @_; # Makes a COPY of the paramter %h= (k1=>'v1', k2=>'v2); # Populates the LOCAL %h, not '%hash' }
my %hash = populate_hash( ); # Option 1: Use the Return value # Option 2: pass a REFERENCE to '%hash', like this: populate_hash(\%hash); # This requires "populate_hash" to be aware of, and use the referenc +e, like this: sub populate_hash{ my ($href) = @_; # Makes a COPY of the reference $href= {k1=>'v1', k2=>'v2}; # Notice - using CURLY brackets, not par +ens. This creates a Hash ref. }
"Battle not with trolls, lest ye become a troll; and if you gaze into the Internet, the Internet gazes also into you."
-Friedrich Nietzsche: A Dynamic Translation
|
|---|