Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Are there argc and argv type functions in perl

by walamab (Initiate)
on Mar 10, 2000 at 19:43 UTC ( #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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://5163]
Approved by root
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2016-12-09 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (158 votes). Check out past polls.