Posted By: lamcro
I’m working on a Perl script. How can I pass command line parameters to it?
script.pl "string1" "string2"
Depends on what you want to do. If you want to use the two arguments as input files, you can just pass them in and then use
<> to read their contents.
If they have a different meaning, you can use
GetOpt::Long to process them easily.
GetOpt::Std supports only single-character switches and
GetOpt::Long is much more flexible. From
use Getopt::Long; my $data = "file.dat"; my $length = 24; my $verbose; $result = GetOptions ("length=i" => $length, # numeric "file=s" => $data, # string "verbose" => $verbose); # flag
@ARGV is a special variable that contains all the command line arguments.
$ARGV is the first (ie.
"string1" in your case) and
$ARGV is the second argument. You don’t need a special module to access