in reply to _ doing something new to me?
Answering the question:
Normal filehandle names in Perl match /[a-z_][a-z0-9_]*/, so it's a legal name, akin to a special variable like $", but a filehandle instead of a scalar. Consider print STDERR "foo\n"... no sigil.
Not answering the question but informative:
It's known as the 'magical underscore filehandle', and it exists for efficiency reasons.
Generally, OS's store a file's metadata all bunched together, in what C programmers would call a 'structure'. Whenever a piece of Perl code requests a part of a file's metadata (e.g. checking its permissions, or checking its size), a system call is made (under *nix, usually called stat() or a derivative like stat64()) that returns the file's complete metadata structure. In the example you posted this is obviously wasteful, so whenever a file test operator is used Perl keeps the returned metadata structure around in memory, in case further tests need to be performed against the same file.
You can learn a lot by using a system call tracer against your Perl code, like strace under Linux. For instance:
# file1.pl my $size = -s $ARGV[0]; my $time = -M $ARGV[0];
$ strace perl file1.pl
# file2.pl my $size = -s $ARGV[0]; my $time = -M _;
$ strace perl file2.pl
... and compare the number of calls to stat() or fstat64() or whatever.
|
|---|