in reply to How portable are common $! error codes?

Most of the time, it is enough to just output the error message in $! to the user, so they can figure out what's happening. If you want to find out more about the exact condition, I'd suggest you use the -X operators, e.g.

die "Can't read $_" unless -r; die "Can't write $_" unless -r; die "Can't execute $_" unless -x; die "$_ not a file" unless -f; die "$_ not a directory" unless -d; # ...

Replies are listed 'Best First'.
Re: Re: How portable are common $! error codes?
by ctilmes (Vicar) on Apr 23, 2003 at 22:19 UTC
    Note, if you call lots of -X operators in succession (i.e. for the same $_), you can use the special filehandle of a single underline to avoid repeating the stat(2) system call:
    die "Can't read $_" unless -r; die "Can't write $_" unless -w _; die "Can't execute $_" unless -x _; die "$_ not a file" unless -f _; die "$_ not a directory" unless -d _;