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::Std
and GetOpt::Long
to process them easily. GetOpt::Std
supports only single-character switches and GetOpt::Long
is much more flexible. From GetOpt::Long
:
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
Alternatively, @ARGV
is a special variable that contains all the command line arguments. $ARGV[0]
is the first (ie. "string1"
in your case) and $ARGV[1]
is the second argument. You don't need a special module to access @ARGV
.
How to delete a newline if it is the last character in a file?
How to efficiently calculate a running standard deviation
Howto use a variable in the replacement side of the Perl substitution operator?
How to summ quickly all numbers in a file?
How to remove duplicate items from an array in Perl?
How to differ of Two Arrays Using Perl
How to escape a forward slash in a regular expression