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.
In reply to Re: Pass by reference question...
by chromatic
in thread Pass by reference question...
by freddo411
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |