bladx has asked for the wisdom of the Perl Monks concerning the following question:

Lately I have been reviewing some of the perl docs, trying to glean out more information about control structures or data structures actually. Whilst doing so, I came accross an interesting command or variable, I'm not sure, called "ARGV". I searched through the entire perl doc containing this entity, but I found no explanation or definition of what it meant or did.

Next, I came here to the monastary to check with super search to see if I could find a post explaining what it was, what it means, and what it does. I searched and searched, however, I did not come up with a definition.

So that brings me to the current. I am curious as to what this operator or variable is? I have no clue as to what it means or stands for, and would appreciate any help or good/interesting nodes to view related to "ARGV"!

Andy Summers

Replies are listed 'Best First'.
Re: What does 'ARGV' mean?
by trantor (Chaplain) on Aug 10, 2001 at 10:08 UTC

    If you want to literally know what it stands for, the answer is ARGument Vector. In programming, vector is generally a synonim for array (especially for BASIC, FORTRAN and C folks).

    The identifier name descends from C, with some differences:

    • it's usually lowercase in C;
    • it's called argv in C just by convention, it could be any other name;
    • it's a local (lexical, auto) variable in C, it belongs to the Main package in Perl;
    • the first element, in the C incarnation, is the program name; Perl stores this value in $0;
    • C needs another parameter, argc, to know how many values are stored in argv; in Perl you can evaluate an array in scalar context to see how many values it contains, or you can use $#array to get the last valid index of teh array itself.

    -- TMTOWTDI

      I can't remember where I saw this -- I think it was an old version of Damian's Perl 6 slides -- but I think Larry may ditch the 'V' and make it 'ARGS'.

      -- Frag.

      A reply falls below the community's threshold of quality. You may see it by logging in.
Re: What does 'ARGV' mean?
by runrig (Abbot) on Aug 10, 2001 at 08:06 UTC
    You must have overlooked something in perldoc perlvar.
      Oh, I didn't check in perlvar, I was looking mostly in: perldata, perlsyn, and perlop ... my fault.

      I apologize for a dumb question. But I am still glad I asked, due to it bothering me for not knowing what it meant.

      Andy Summers
Re: What does 'ARGV' mean?
by TStanley (Canon) on Aug 10, 2001 at 08:08 UTC
    @ARGV is a special variable in Perl that stores arguments, either from the command line when you first initiate the script. For example:
    #!/usr/bin/perl -w use strict; my $length = @ARGV; ## If the number of arguments is less than two, it dies ## else it shifts them off of the array and into the ## variables if($length<2){ die"Not enough arguements!\n"; }else{ my $arg1 = shift; my $arg2 = shift; }
    UPDATE: Corrected variable name.
    UPDATE 2: And as runrig reminded me, there is also a $ARGV variable which contains the filename of an open file when you call it like this: <>

    TStanley
    --------
    There's an infinite number of monkeys outside who want to talk to us
    about this script for Hamlet they've worked out
    -- Douglas Adams/Hitchhiker's Guide to the Galaxy