|
|
| laziness, impatience, and hubris | |
| PerlMonks |
Comment on |
| ( #3333=superdoc: print w/ replies, xml ) | Need Help?? |
|
Arguments are passed into a subroutine via @_. Accessing one element or more of that array can be done in two ways, non-destructive (the @_ array persists as passed in) or destructive (the @_ array is consumed during assignment):
If @_ needs to be intact for subsequent calls, as in
the non-destructive methods are used. Also, as the variables passed in via the vector @_ are Otherwise, it just doesn't matter. Since after setting up the variables in the sub's scope @_ isn't looked at anymore, arguments may be shifted or not. In these cases saying $var = shift or $var = $_[0] does the same for the sub, although the impact on @_ is different. So, saying $var = shift and @list = @_ is just caring about copying, but done that, not caring about @_ any more. Using the arguments in a sub without prior assignment (i.e. without copying, as $_[0] .. $_[$#_]) modifies the thingies in the caller. --shmem <update> changed reference to alias as per tye's post </update>
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re: shift vs @_
by shmem
|
|