Note: I do NOT want to modify any keys of the passed in hash. (then it would be a newbie question). I'm trying to completely replace it with a totally new hash. I want to change the target of the reference, to a new hash.#I have a hash, %myhash; #I pass it by reference: mergetwohashes(\%myhash, \%b); sub mergetwohashes { my($a)=$_[0]; my($b)=$_[1]; $a = { %{$a}, %{$b} }; } #After I call the function, %myhash is unchanged. Why.
I also tried derefencing it as if it was a scalar reference, but perl complains "not a scalar reference", as you might guess.
I also tried the method call like this:
mergetwohashes(%myhash, \%b);
mergetwohashes($myhash, \%b);
Just in case the backslash operator was doing something I didn't expect, but no.
Is this something deeper- does the Perl call stack not support this because the passed in @_ array is immutable? What's my workaround here?
thank you
In reply to Modify hash reference itself by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |