@ARGV would be an Array with four entries like this right?
Yes, except for the new lines, \n.
Prove this to yourself with a test script:
use strict;
use warnings;
print "These are the ", scalar @ARGV, " arguments:\n";
my $i = 0;
for (@ARGV) {
print "ARGV[$i] = $_\n";
$i++;
}
prints:
These are the 4 arguments:
ARGV[0] = s/foo/bar/
ARGV[1] = file1.txt
ARGV[2] = file2.txt
ARGV[3] = file3.txt
Alternately, you can use Data::Dumper:
use strict;
use warnings;
use Data::Dumper;
print Dumper(\@ARGV);
prints:
$VAR1 = [
's/foo/bar/',
'file1.txt',
'file2.txt',
'file3.txt'
];
What I do not understand is how the script determines which
files to put into @ARGV. At which point is "*.txt" being evaluated?
Or is it the shell that tells the script which files in the directory
match the pattern *.txt?
The shift built-in function removes element 0 from the @ARGV
array, shifting the remaining elements [1:3] down to new positions [0:2].
Again, here is a simple test script:
use strict;
use warnings;
my $op = shift;
# same as: my $op = shift @ARGV;
print "These are the ", scalar @ARGV, " arguments:\n";
my $i = 0;
for (@ARGV) {
print "ARGV[$i] = $_\n";
$i++;
}
prints:
These are the 3 arguments:
ARGV[0] = file1.txt
ARGV[1] = file2.txt
ARGV[2] = file3.txt
|