Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Are there argc and argv type functions in perl

by walamab (Initiate)
on Mar 10, 2000 at 19:43 UTC ( [id://5163]=perlquestion: print w/replies, xml ) Need Help??

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

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: perlquestion [id://5163]
    Approved by root
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others romping around the Monastery: (3)
    As of 2024-04-19 04:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found