The @ARGV Variable
The special variable @ARGV contains the command-line arguments for the program. For example, if you run a script with the command
$ perl doit.pl alpha beta gamma
Then
$ARGV[0] = "alpha"; $ARGV[1] = "beta"; $ARGV[2] = "gamma";
To get the number of arguments, use the notation $#ARGV (there is no argc). Note that unlike in C programming, the first argument is not the name of the program. If you need the name of the program, it’s assigned to the variable $0.
Get Perl for C Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.