Because the assignment copies the values, this also has the effect of turning call-by-reference into call-by-value. Otherwise a function is free to do in-place modifications of "@_" and change its caller's values.sub maybeset { my($key, $value) = @_; $Foo{$key} = $value unless $Foo{$key}; }
But if this is the case, then how come
actually updates the anonymous hashref that was passed in? Supposedly the assignment changed call by reference to call by value and hence any edits to $self should not have affected the caller.sub XXX { my ($self) = @_; $self->{age} = '17'; }
I do this all the time and it just struck me that it shouldn't work.
In reply to How does my $self = (@_) actually work? by princepawn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |