Hmm.. perl doesn't make this easy though.
open() returns undef on failure, that's it.
Now that's not terribly useful - I have to treat a non-existant file separately to other errors, so I either have to check $! or test -f without introducing a race condition.
Ok, so I could go to something like this:
use Errno;
unless ( open(INFILE, "<", $filename) )
{
return if exists &Errno::ENOENT && $! + 0 == &Errno::ENOENT;
return unless -f $filename;
die "open failed: $!";
}
Not great, but more portable. Makes use of Errno::ENOENT if its available but fallbacks to a simple -f as a last resort.
So, any suggestions for improvements???
In reply to Re: Re: How portable are common $! error codes?
by Anonymous Monk
in thread How portable are common $! error codes?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |