http://qs321.pair.com?node_id=5163

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

I'm trying to take parameters from the command line at execution. Is this possible with perl? If so, how is it done? Thanks!
  • Comment on Are there argc and argv type functions in perl

Replies are listed 'Best First'.
Re: Are there argc and argv type functions in perl
by btrott (Parson) on Mar 10, 2000 at 22:41 UTC
    No such thing as $ARGC, as far as I know.

    But yes, you can use @ARGV to get the command line args. Something to be aware of is that

    $ARGV[0]
    is not the command name; it's the first argument.

    Also, check out the Getopt family of modules for automatically parsing your command line args:

    perldoc Getopt::Std perldoc Getopt::Long
    and more.
RE: Are there argc and argv type functions in perl
by Anonymous Monk on Mar 11, 2000 at 01:36 UTC
    $#argv is the same as argc. And as mentioned by another poster, $argv[0] is not the command name, rather $0 is.
RE: Are there argc and argv type functions in perl
by Anonymous Monk on Mar 12, 2000 at 00:14 UTC
    try the @ARGV array. $ARGV[0] is the first commandline parameter, though.
      my $argc = @ARGV; print "There are $argc args.\n";
        Nice, you answered a ten-year old, already perfectly answered question with an unnecessary two-liner... ;-)
RE: Are there argc and argv type functions in perl
by Anonymous Monk on Mar 11, 2000 at 00:43 UTC
    while(<>) { } This will allow you to read input from the command line, its all in the camel book, a must have for all level of perl programmer.
Re: Are there argc and argv type functions in perl
by pschoonveld (Pilgrim) on Mar 10, 2000 at 22:28 UTC