On Mon, Jun 04, 2001 at 08:02:36PM +0000, George Petri wrote:
> 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.

This is, as your experimentation has shown, false.  Command-line arguments
populate @ARGV.  The description of shift is correct, but only in certain
situations.

 
> 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"?

Reading the documentation on shift will answer your question.

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


Basically, Perl does what you mean depending on where your argument-less
shift is.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to