in reply to Re: How portable are common $! error codes?
in thread How portable are common $! error codes?
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???
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: How portable are common $! error codes?
by Anonymous Monk on Apr 24, 2003 at 10:49 UTC | |
by ctilmes (Vicar) on Apr 24, 2003 at 11:24 UTC | |
|
Re: Re: Re: How portable are common $! error codes?
by Necos (Friar) on Apr 24, 2003 at 17:27 UTC |