in reply to How does my $self = (@_) actually work?
If you pass in a hashref as the first argument, $_[0] refers to aliases that scalar. The lexically scoped copy produces a second hashref to the same external hash.
Some variations:
sub XXX { my ($self) = @_; $self->{age} = '17'; # does as you say $_[0]->{'age'} = '21'; # a miraculous drivers license $self = { %{$self} }; # now we have a copy of the innards $self->{age} = '17'; # restoration of youth # the world now thinks age=>21, we have private age=>17 # Youth will be lost when the sub exits }
Hope that helps.
After Compline,
Zaxo
Update: Ovid uses 'alias', and it's a better term for it. Less chance of confusion.
|
|---|