Perl command line arguments stored in the special array called @ARGV.
ARGV example
Use $ARGV[n] to display argument.
Use $#ARGV to get total number of passed argument to a perl script.
For example, if your scriptname is foo.pl and you called script as follows:
./foo.pl one two three
You can print one, two, three command line arguments with print command:
print “$ARGV[$0]\n”;
print “$ARGV[$1]\n”;
print “$ARGV[$2]\n”;
Or just use a loop to display all command line args:
#!/usr/bin/perl -w
foreach $num (0 .. $#ARGV) {
print “$ARGV[$num]\\n”;
}
Advertisements