If I understood you question properly you want to know why people use
shift in subrutines and how does shift work.

I will try to make it short:
shift works on lists, it removes the first element of the list ( the 0
indexed element ) and returns it as a lvalue ( if there are no more
elements in a list it returns undef ).
Here is an example:

my @list = qw(a b c d);
print shift @list,"\n";
print "my list is now @list\n";
print shift @list,"\n";
print "my list is now @list\n";
print shift @list,"\n";
print "my list is now @list\n";
print shift @list,"\n",
print "my list is now @list\n";

this should print something like this ( althoug I did not have the
time to test it )
a
my list is now b c d
b
my list is now c d
c
and so on...
If you use shift without giving it the list name to work on it will
refer to @_ or @ARGV ( it is decided upon the file scope ). So when
you define a sub like this:

sub somesub {
my $arg1 = shift;
}

You did something simmilar to my $arg1 = $_[0]; but more elegant ( in
my opinion ) and you removed the first element from the arguments list
( witch is quite usefull ).

Hope this will clear some things up, you can check also:
perldoc -f shift
perldoc -f unshift
perldoc -f pop
perldoc -f push

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to