Note: if you pass SEVERAL file names to your script, like:
$ script.pl file1 file2 file3
Then the script will read through ALL of them, in sequence,
almost as if they were all one long concatinated file.
The <> token pulls a line of input from the current file.
In the process, it gets rid of $ARGV[0], and shifts the
other filenames to the left, so they can be used next.
The input from each file is processed, and the name is
discarded. So, when you saved $ARGV[0] to another variable
before the loop, it was still around to be printed later.
BTW, the variable $1, in shell scripting is not safe from
change either... The command word "shift" will do the same
sort of thing - discarding $1, and moving $2... in its place.
Also, if you say "$set apple pear orange plum" then all of
the $1 .. $n arguments will be discarded, and replaced, with
$1=apple $2=pear $3=orange $4=plum (Is nothing sacred ?!?!?)
|