Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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
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 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 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... ;-)

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (15)
As of 2014-09-22 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls