⭐ in reply to How do you use command line parameters?
The @ARGV array holds the command-line arguments, and in this case, it would hold ('foo', 'bar', 'blat').% ./myprog foo bar blat
Here's a sample run:#!/usr/bin/perl -s print "value of -x: $x\n"; print "value of -name: $name\n";
If you want more complex option parsing, there are two standard modules that can do this for you: Getopt::Std and Getopt::Long.% ./myprog -x -name=Jeff value of -x: 1 value of -name: Jeff
while (<>) { # $ARGV is the filename # $_ is the line # $. is the line number # reset it to 0 by doing # $. = 0 if eof; # or # close ARGV if eof; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Answer: How do you use command line parameters?
by japhy (Canon) on Sep 20, 2000 at 18:52 UTC |