in reply to Pass by reference question...
The output (below) shows that the attempt to assign a new hashref fails silently.
No, it works:
sub assign_new_href { my $href = shift; $href = { new_key => 4 } ; }
Within that function, you do assign a new hash reference to the lexical $href. However it doesn't modify the hash to which $href refers because that's not how references work. Think of $href as a container. You've dumped out its contents to replace those contents with something else. What you want to do is replace the contents of its contents with something else:
sub assign_new_href { my $href = shift; %$href = ( new_key => 4 ); }
Improve your skills with Modern Perl: the free book.
|
|---|