@ARGV is an array, so you need to read the data as an array. One way is:
#!/usr/bin/perl -w
#
# input from command line
#
my ( $foo, $bar ) = @ARGV;
print "foo = $foo\n";
print "bar = $bar\n";
You could also use $ARGV[0], 1, etc, and use $#ARGV to know how many arguments you have. Another way is just to use shift:
#!/usr/bin/perl -w
#
# input from command line
#
my $foo = shift;
my $bar = shift;
print "foo = $foo\n";
print "bar = $bar\n";
Now, if you're serious about command line input, I'd suggest looking at Getopt::Long. and perhaps Pod::Usage. A piece of the beginning of one of my work scripts might look like:
#!/usr/bin/perl
#
# embed perdoc somewhere (top or bottom) for script documentation.
#
use warnings;
use strict;
use Getopt::Long;
use Pod::Usage;
my $help = 0;
my $man = 0;
GetOptions('help|?' => \$help, man => \$man ) or pod2usage(2);
pod2usage(-exitval => 0, -verbose => 1) if $help;
pod2usage(-exitval => 0, -verbose => 2) if $man;
my $file = shift;
pod2usage(-exitfile => 1, -verbose => 1) unless ( defined( $file ));
die("File $file is not a regular file.\n") unless ( -f $file );
Update: cleanup and typo fixes |