Just thought I'd write a note about this, so that Google might warn others about it.
There is a bug in the Perl standard module File::stat. It is present at least in the version that comes with Perl 5.6.1, and has been fixed in the version that comes with Perl 5.8.1.
The trouble is, it doesn't detect properly errors in stating
the file (in the stat sub it provides to override the
built-in one). It assumes that if the call to the built-in stat
fails, then you must have passed it a file handle rather than
a filename.
Here is a sample program which demonstrates the problem:
#!/usr/bin/perl -w use strict; use File::stat; my $s = stat('/this/does/not/exist') or die "Error stating file: $!\n"; print "Size: ", $s->size, "\n";
Symptoms
If warnings are turned on, as above, then the attempt to use the filename as a file handle (after using it as a filename has failed) will make Perl print a warning like this:
stat() on unopened filehandle /this/does/not/exist at /usr/share/perl/5.6.1/File/stat.pm line 49.
Whether or not warnings are turned on, the stat sub will
return false to indicate an error, but $! will already have
been emptied by the second call to the built-in stat.
Solution
Don't use File::stat unless you know you won't be using Perl 5.6.1.
Go back to the old-fashioned stat function, ugly though it is.