* Dylan Stamat <[EMAIL PROTECTED]> [2005-11-13T22:19:17] > No, not the routine that deals with Arrays !
If you don't know what it is, why are you making assumptions, or telling
us what it isn't? If you don't know, don't assume!
> I see code like the following, everywhere:
> my $coolvariable = shift;
Did you look at the documentation for shift? The built-in functions are
well-documented in perldoc:
from the output of "perldoc -f shift"
shift ARRAY
shift Shifts the first value of the array off and
returns it, shortening the array by 1
and moving everything
down. If there are no elements in the
array, returns the
undefined value. If ARRAY is omitted,
shifts the @_ array
within the lexical scope of
subroutines...
In other words, it IS the routine that deals with arrays. The arguments
to a subroutine are available in the @_ array.
sub do_something_cool {
my $coolvariable = shift;
go_under($coolvariable); # you're right, mark, that is cool
print "down under where the lights are $coolvariable\n";
}
If I call do_something_cool("low"), execution will move to the
do_something_cool sub, with @_ = ("low"). shift will take the argument
from the stack and put it in the newly-declared lexical.
It will do something, then print the line with "low" interpolated into
it.
--
rjbs
pgpWItKqzF672.pgp
Description: PGP signature
