[PLUG] Working with learning Perl by Randal Schwartz...
Felix Lee
felix.1 at canids.net
Sat Oct 25 18:48:02 UTC 2003
"Michael C. Robinson" <michael at goose.robinson-west.com>:
> In the examples for a simple client and server what do the
> lines "my $client = shift;" do?
at compile-time
declare $client as a lexically local variable
at run-time
assign to $client the value returned by the builtin operator 'shift'
which returns the first element of @_
and removes it from @_
@_ is the array of arguments passed to the function,
which are passed by value
and @_ is a dynamically local variable
so modifying @_ like that will not change anything in the caller
except
if the caller uses a "& foo" style function call without ()
then the callee gets the same @_ as the caller,
so modifying @_ also modifies the caller's @_
'shift' will use @ARGV instead of @_
if it's used lexically outside a function or format
or within an 'eval $string' statement
(but not an 'eval {block}' statement)
or within the special forms BEGIN, INIT, CHECK, END.
--
More information about the PLUG
mailing list