A bit of a different explanation...
Let's pretend we are in Perl4 so there are no \ and -> operators to deal with references so we can use them to talk about how Perl itself deals with aliases.
Then calling test($x,$y,$z) sets @_ to (\$x,\$y,\$z). So if you do $_[0]= "new val" without having modified @_ then you end up doing ${\$x}= "new val" because Perl will see that $_[0] currently contains a reference to (alias of) $x and so modifying $_[0] also modifies $x.
Well if you do my $x1= shift then you are left with @_ containing (\$y,\$z). Do that two more times and @_ is empty. So $_[0]= "new val" ends up putting a value into @_ where no value was before. So there is no reference (alias) for Perl to implicitly dereference so, of course, $x is not changed in that case. So you end up with @_ having ("new val") or ("x2","y2","z2") and @_ just gets thrown away in the end.
Also, when @_ is empty, doing $_[0]= "x" finds $_[0] not being an alias to anything and so creates a new scalar and sets $_[0] to be an alias to it (the only alias at that point).
I hope that helps some.
Update: And calling test(@v) sets @_ to (\$v[0],\$v[1],\$v[2]) (if @v has three elements) (which could be written as \(@v) in Perl5). But doing @_= @v copies the values rather than making aliases.
- tye (but my friends call me "Tye")In reply to (tye)Re: Calling subroutine in a package from other perl sub.
by tye
in thread Calling subroutine in a package from other perl sub.
by Anonymous Monk
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |