Hi George,

Perldoc -f shift gives you:

=item shift ARRAY
 
=item 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
C<@_> array within the lexical scope of subroutines and formats, and the
C<@ARGV> array at file scopes or within the lexical scopes established 
by
the C<eval ''>, C<BEGIN {}>, C<END {}>, and C<INIT {}> constructs.
See also C<unshift()>, C<push()>, and C<pop()>.  C<Shift()> and 
C<unshift()> do
the
same thing to the left end of an array that C<pop()> and C<push()> do 
to the
right end. 

This basically means that if you are inside a subroutine it defaults to 
@_ and @ARGV if you are not in a subroute (the perl equiv of C's 
main()).

That's the way I read it anyway.

Which means (based on what you said) that the book must be wrong as @_ 
doesn't work while @ARGV does.

Gary.

On Monday 04 June 2001  9:02 pm, George Petri wrote:
> Hi!
>
> In a book called "Open Source Linux Web Porgramming" by Jones and
> Batchelor, it says (on Page 61):
>
> "When you launch a script from the command line, for example, @_
> populates with all of the parameters passed in through the command
> line.  The shift function, among others, will use @_ by default if no
> other array is provided.
>
> #!/usr/bin/perl
> @firstCommandLineArg=shift;
> @secondCommandLineArg=shift;"
>
> The provided code snipplet works but if I use "shift @_" (since @_ is
> supposedly used by default anyway), I do not get the command line
> arguments.
>
> However, if I use "shift @ARGV", I DO get the command line arguments.
>  If the shift function really does use @_ as its default argument,
> then why did shift in the example code, use @ARGV as default?  Does
> @_ really get populated "with all of the parameters passed in through
> the command line"?
>
> Thanks,
> George Petri

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 
    

Reply via email to