in reply to Shift function and file opening
The answer to this can be found in perlfunc:shift.
Shifts the first value of the array off and returns it, shortening the array by 1 and moving everything down. If there are no elements in the array, returns the undefined value. If ARRAY is omitted, shifts the @_ array within the lexical scope of subroutines and formats, and the @ARGV array at file scopes or within the lexical scopes established by the eval '', BEGIN {}, INIT {}, CHECK {}, and END {} constructs.
What that means is that if your snippet of code is at "file scope", that is to say, not inside a subroutine, then the shift function will operate upon the array @ARGV. In your snippet, it checks to see if a filename was supplied to the program and if it was, then it opens that file. However, if no argument was supplied on the command line, then shift @ARGV will return undef, and the || 'foo.html'; part of the statement comes into play and $file is set to that, and that is the file that will be opened if it exists. If it doesn't, the the program will die with an error message explaning why.
|
|---|