Book Home Programming PerlSearch this book

32.14. Errno

use Errno;
unless (open(FH, $pathname)) {
    if ($!{ENOENT}) {  # We don't need an import for this!
        warn "$pathname does not exist\n";
    }
    else {
        warn "open failed on `$pathname': $!";
    }
}

use Errno qw(EINTR EIO :POSIX);
if ($! == ENOENT) { .... }
The Errno module makes available the symbolic names for the error status values set when a syscall fails, but does not export them by default. The module has a single export tag, ":POSIX", which exports only those symbols defined by the POSIX 1003.1 standard. The module also makes the global %! variable magical using tie. You can subscript into the %! hash using any valid errno on your system, not just the POSIX ones, and its value is true only if that's the current error.



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.