shift returns the first value of the array. When no array is defined it
operates on the default array @_

You will most likely see the line you mention as the first line of a
subroutine. E.g

&call_sub('John');

sub call_sub {
        my $name = shift;
        print "Name is $name\n";
}

What's happening here is that the value passed to the subroutine call_sub is
stored in a locally scoped default array for that subroutine. When you
perform a shift on the array it returns the data passed. This is stored in
the local $name scalar for use within the subroutine. Some other ways you
may see this written are

my $name = $_[0];       # Uses a direct route to the first element of the
array
my ($one, $two) = @_; # When passing more than one value to the subroutine,
assign them to two different scalars within the array

HTH

John

-----Original Message-----
From: Wim De Hul [mailto:[EMAIL PROTECTED]]
Sent: 20 December 2001 15:48
To: [EMAIL PROTECTED]
Subject: Shift question...


Hello guys ( and girls),

While I was reading a script, I saw the lines:

my $var = shift;

I thought that shift puts a variable in an array? What does this mean?

Thanks,

Wim.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------Confidentiality--------------------------.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to