![]() |
|
Perl-Sensitive Sunglasses | |
PerlMonks |
Re: what does shift do?by dmmiller2k (Chaplain) |
on May 19, 2002 at 20:27 UTC ( #167706=note: print w/replies, xml ) | Need Help?? |
shift applies to an array, as in, shift @a or, shift(@a). It removes the first (i.e., 0th) element from the array, shifting the remaining elements back by one (hence the name, I suppose), and returns the first element as its value.
So, if you have an array, initialized like this:
then after this code executes, $x will contain the scalar value, 'a', and @a will contain, ( 'b', 'c' ). In lexical scope (i.e., within a subroutine), shift by itself, without any arguments, implicitly acts upon the variable @_, which contains the subroutine's arguments. At file scope (i.e., outside of any subroutine), it implicitly operates instead upon @ARGV (also known as ::@ARGV, or main::@ARGV), which contains the command line parameters passed to the script. See the docs, "shift". dmm There are no stupid questions -- just stupid-making responses
In Section
Seekers of Perl Wisdom
|
|