Perldoc Search: "$!" perl-5.20.1

search official POD


31 PODs, 294 LINEs found.
perlipc.pod
47 :     Signal number zero may fail because you lack permission to send the signal when directed at a process whose real or saved UID is not identical to the real or effective UID of the sending process, even though the process is alive. You may be able to determine the cause of failure using $! or "%!".
49 :         unless (kill(0 => $pid) || $!{EPERM}) {
76 :             # don't change $! and $? outside handler
77 :             local ($!, $?);
107 :                             || die "cannot flock: $!";
138 :           exec($SELF, @ARGV)        || die "$0: couldn't restart: $!";
182 :                   || die "Error setting SIGALRM handler: $!\n";
187 :         On systems that supported it, older versions of Perl used the SA_RESTART flag when installing %SIG handlers. This meant that restartable system calls would continue rather than returning when a signal arrived. In order to deliver deferred signals promptly, Perl 5.8.0 and later do *not* use SA_RESTART. Consequently, restartable system calls can fail (with $! set to "EINTR") in places where they previously would have succeeded.
205 :         mkfifo($path, 0700)     ||  die "mkfifo $path failed: $!";
230 :                                     || die "can't mkfifo $FIFO: $!";
234 :             open (FIFO, "> $FIFO")  || die "can't open $FIFO: $!";
236 :             close(FIFO)             || die "can't close $FIFO: $!";
244 :                             || die "can't fork: $!";
247 :         close SPOOLER       || die "bad spool: $! $?";
252 :                             || die "can't fork: $!";
257 :         close STATUS        || die "bad netstat: $! $?";
274 :         open(FH, "|bogus")      || die "can't fork: $!";
277 :         close(FH)               || die "can't close: $!";
282 :         open(FH, "|bogus")  || die "can't fork: $!";
302 :             chdir("/")                      || die "can't chdir to /: $!";
303 :             open(STDIN,  "< /dev/null")     || die "can't read /dev/null: $!";
304 :             open(STDOUT, "> /dev/null")     || die "can't write to /dev/null: $!";
305 :             defined(my $pid = fork())       || die "can't fork: $!";
307 :             (setsid() != -1)                || die "Can't start a new session: $!";
308 :             open(STDERR, ">&STDOUT")        || die "can't dup stdout: $!";
326 :                 warn "cannot fork: $!";
339 :                                     || die "can't open $PRECIOUS: $!";
343 :             close(OUTFILE)          || die "can't close $PRECIOUS: $!";
352 :         defined($pid)           || die "can't fork: $!";
363 :                                 || die "can't exec program: $!";
370 :         defined($pid)           || die "can't fork: $!";
381 :                                 || die "can't exec program: $!";
390 :         defined($pid)               || die "first fork failed: $!";
393 :                 defined($sub_pid)   || die "second fork failed: $!";
394 :                 close(WRITER)       || die "couldn't close WRITER: $!";
401 :                 close(WRITER)       || die "couldn't close WRITER: $!";
416 :         pipe(READER, WRITER)        || die "pipe failed: $!";
418 :         defined($pid)               || die "first fork failed: $!";
422 :                 defined($sub_pid)   || die "first fork failed: $!";
423 :                 close(WRITER)       || die "can't close WRITER: $!";
429 :                 close(WRITER)       || die "can't close WRITER: $!";
435 :             open(STDIN, "<&READER") || die "can't reopen STDIN: $!";
436 :             close(WRITER)           || die "can't close WRITER: $!";
445 :         open(PS_PIPE, "ps aux|")    || die "can't open ps pipe: $!";
450 :                                     || die "can't open ps pipe: $!";
454 :                                     || die "can't open @ps_args|: $!";
462 :                             || die "can't open @grep_args|: $!";
522 :             die "cannot fork: $!" unless defined $pid;
546 :                                     ||  die "socketpair: $!";
559 :             die "cannot fork: $!" unless defined $pid;
598 :         socket(SOCK, PF_INET, SOCK_STREAM, $proto)  || die "socket: $!";
599 :         connect(SOCK, $paddr)               || die "connect: $!";
604 :         close (SOCK)                        || die "close: $!";
623 :         socket(Server, PF_INET, SOCK_STREAM, $proto)    || die "socket: $!";
625 :                                                         || die "setsockopt: $!";
626 :         bind(Server, sockaddr_in($port, INADDR_ANY))    || die "bind: $!";
627 :         listen(Server, SOMAXCONN)                       || die "listen: $!";
664 :         socket(Server, PF_INET, SOCK_STREAM, $proto)    || die "socket: $!";
666 :                                                         || die "setsockopt: $!";
667 :         bind(Server, sockaddr_in($port, INADDR_ANY))    || die "bind: $!";
668 :         listen(Server, SOMAXCONN)                       || die "listen: $!";
679 :             local $!;   # don't let waitpid() overwrite current error
691 :                 next if $!{EINTR};
692 :                 die "accept: $!";
705 :                     or confess "can't exec fortune: $!";
719 :                 logmsg "cannot fork: $!";
738 :     If accept() is interrupted by a signal, $! will be set to EINTR. If this happens, we can safely continue to the next iteration of the loop and another call to accept(). It is important that your signal handling code not modify the value of $!, or else this test will likely fail. In the REAPER subroutine we create a local version of $! before calling waitpid(). When waitpid() sets $! to ECHILD as it inevitably does when it has no more children waiting, it updates the local copy and leaves the original unchanged.
765 :                                                 || die "socket: $!";
766 :             connect(SOCKET, $hispaddr)          || die "connect: $!";
794 :         socket(SOCK, PF_UNIX, SOCK_STREAM, 0)     || die "socket: $!";
795 :         connect(SOCK, sockaddr_un($rendezvous))   || die "connect: $!";
816 :         socket(Server, PF_UNIX, SOCK_STREAM, 0) || die "socket: $!";
818 :         bind  (Server, $uaddr)                  || die "bind: $!";
819 :         listen(Server, SOMAXCONN)               || die "listen: $!";
845 :                 exec("/usr/games/fortune")  || die "can't exec fortune: $!";
858 :                 logmsg "cannot fork: $!";
985 :                    || die "can't connect to port $port on $host: $!";
991 :         die "can't fork: $!" unless defined($kidpid = fork());
1103 :         socket(SOCKET, PF_INET, SOCK_DGRAM, $proto)   || die "socket: $!";
1104 :         bind(SOCKET, $paddr)                          || die "bind: $!";
1113 :             defined(send(SOCKET, 0, 0, $hispaddr))    || die "send $host: $!";
1122 :             $hispaddr = recv(SOCKET, $rtime, 4, 0)    || die "recv: $!";
1142 :         defined($id)                    || die "shmget: $!";
1146 :         shmwrite($id, $message, 0, 60)  || die "shmwrite: $!";
1148 :         shmread($id, $buff, 0, 60)      || die "shmread: $!";
1157 :         shmctl($id, IPC_RMID, 0)        || die "shmctl: $!";
1165 :         defined($id)                    || die "semget: $!";
1174 :         defined($id)                    || die "semget: $!";
1189 :         semop($id, $opstring)   || die "semop: $!";
1208 :         semop($id, $opstring)   || die "semop: $!";
1217 :         defined($id)                || die "msgget failed: $!";
1223 :                                     || die "msgsnd failed: $!";
1226 :                                     || die "msgrcv failed: $!";
1236 :         msgctl($id, IPC_RMID, 0)    || die "msgctl failed: $!\n";
perlfunc.pod
30 :     In general, functions in Perl that serve as wrappers for system calls ("syscalls") of the same name (like chown(2), fork(2), closedir(2), etc.) return true when they succeed and "undef" otherwise, as is usually mentioned in the descriptions below. This is different from the C interfaces, which return -1 on failure. Exceptions to this rule include "wait", "waitpid", and "syscall". System calls also set the special $! variable on failure. Other functions do not, except accidentally.
121 :     -X  A file test, where X is one of the letters listed below. This unary operator takes one argument, either a filename, a filehandle, or a dirhandle, and tests the associated file to see if something is true about it. If the argument is omitted, tests $_, except for "-t", which tests STDIN. Unless otherwise documented, it returns 1 for true and '' for false. If the file doesn't exist or can't be examined, it returns "undef" and sets $! (errno). Despite the funny names, precedence is the same as any other named unary operator. The operator may be any of:
222 :         If you want to use "alarm" to time out a system call you need to use an "eval"/"die" pair. You can't rely on the alarm causing the system call to fail with $! set to "EINTR" because Perl sets up signal handlers to restart system calls on some systems. Using "eval"/"die" always works, modulo the caveats given in "Signals" in perlipc.
258 :         Arranges for FILEHANDLE to be read or written in "binary" or "text" mode on systems where the run-time libraries distinguish between binary and text files. If FILEHANDLE is an expression, the value is taken as the name of the filehandle. Returns true on success, otherwise it returns "undef" and sets $! (errno).
447 :         If the filehandle came from a piped open, "close" returns false if one of the other syscalls involved fails or if its program exits with non-zero status. If the only problem was that the program exited non-zero, $! will be set to 0. Closing a pipe also waits for the process executing on the pipe to exit--in case you wish to look at the output of the pipe afterwards--and implicitly puts the exit status value of that command into $? and "${^CHILD_ERROR_NATIVE}".
456 :                 or die "Can't start sort: $!";
459 :                 or warn $! ? "Error closing sort pipe: $!"
462 :                 or die "Can't open 'foo' for input: $!";
565 :                 or die "Can't open netscape history file: $!";
588 :             die "Can't readlink $sym: $!"
656 :             die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
657 :             chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
680 :         If an uncaught exception results in interpreter exit, the exit code is determined from the values of $! and $? with this pseudocode:
682 :             exit $! if $!;              # errno
686 :         The intent is to squeeze as much possible information about the likely cause into the limited space of the system exit code. However, as $! is the value of C's "errno", which can be set by any system call, this means that the value of the exit code used by "die" can be non-predictable, so should not be relied upon, other than to be non-zero.
729 :         If "do" can read the file but cannot compile it, it returns "undef" and sets an error message in $@. If "do" cannot read the file, it returns undef and sets $! to the error. Always check $@ first, as compilation could fail in a way that also sets $!. If the file is successfully compiled, "do" returns the value of the last expression evaluated.
741 :                     warn "couldn't do $file: $!"    unless defined $return;
924 :             exec ('foo')   or print STDERR "couldn't exec foo: $!";
925 :             { exec ('foo') }; print STDERR "couldn't exec foo: $!";
1060 :                 or die "can't fcntl F_GETFL: $!";
1071 :                         or die "Can't get flags for the socket: $!\n";
1074 :                         or die "Can't set flags for the socket: $!\n";
1120 :                 flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n";
1123 :                 seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n";
1128 :                 flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n";
1132 :                 or die "Can't open mailbox: $!";
1181 :         Returns the next character from the input file attached to FILEHANDLE, or the undefined value at end of file or if there was an error (in the latter case $! is set). If FILEHANDLE is omitted, reads from STDIN. This is not particularly efficient. However, it cannot be used by itself to fetch single characters without waiting for the user to hit enter. For that, try something more like:
1351 :         The function returns a packed string representing the requested socket option, or "undef" on error, with the reason for the error placed in $!. Just what is in the packed string depends on LEVEL and OPTNAME; consult getsockopt(2) for details. A common case is that the option is an integer, in which case the result is a packed integer, which you can decode using "unpack" with the "i" (or "I") format.
1361 :                 or die "getsockopt TCP_NODELAY: $!";
1774 :         Creates the directory specified by FILENAME, with permissions specified by MASK (as modified by "umask"). If it succeeds it returns true; otherwise it returns false and sets $! (errno). MASK defaults to 0777 if omitted, and FILENAME defaults to $_ if omitted.
1869 :                 or die "cannot open < input.txt: $!";
1874 :                 or die "cannot open > output.txt: $!";
1897 :             || die "can't open UTF-8 encoded filename: $!";
1910 :                || warn "close failed: $!";
1915 :                or die "cannot open < input.txt: $!";
1922 :             open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
1940 :                 or die "Can't open STDOUT: $!";
1948 :                 or die "Can't open 'dbase.mine' for update: $!";
1951 :                 or die "Can't open 'dbase.mine' for update: $!";
1954 :                 or die "Can't start caesar: $!";
1957 :                 or die "Can't start caesar: $!";
1960 :                 or die "Can't start sort: $!";
1964 :                 or die "Can't open memory file: $!";
1977 :                     print STDERR "Can't open $filename: $!\n";
1998 :             open(my $oldout, ">&STDOUT")     or die "Can't dup STDOUT: $!";
1999 :             open(OLDERR,     ">&", \*STDERR) or die "Can't dup STDERR: $!";
2001 :             open(STDOUT, '>', "foo.out") or die "Can't redirect STDOUT: $!";
2002 :             open(STDERR, ">&STDOUT")     or die "Can't dup STDOUT: $!";
2010 :             open(STDOUT, ">&", $oldout) or die "Can't dup \$oldout: $!";
2011 :             open(STDERR, ">&OLDERR")    or die "Can't dup OLDERR: $!";
2044 :             $child_pid = open(FROM_KID, "-|")   // die "can't fork: $!";
2048 :             $child_pid = open(TO_KID,   "|-")   // die "can't fork: $!";
2080 :                 // die "Can't open pipeline to lpr: $!";
2093 :             open(FH, $filename) or die "Can't open $filename: $!";
2098 :                 || die "can't open < $file: $!";
2104 :                 || die "open failed: $!";
2108 :             open(IN, $ARGV[0]) || die "can't open $ARGV[0]: $!";
2113 :                 || die "can't open < $ARGV[0]: $!";
2121 :                 or die "sysopen $path: $!";
2749 :         Attempts to read LENGTH *characters* of data into variable SCALAR from the specified FILEHANDLE. Returns the number of characters actually read, 0 at end of file, or undef if there was an error (in the latter case $! is also set). SCALAR will be grown or shrunk so that the last character actually read is the last character of the scalar after the read.
2762 :             opendir(my $dh, $some_dir) || die "can't opendir $some_dir: $!";
2789 :         If "readline" encounters an operating system error, $! will be set with the corresponding error message. It can be helpful to check $! when you are reading from filehandles you don't trust, such as a tty or a socket. The following example uses the operator form of "readline" and dies if the result is not defined.
2792 :                 defined( $_ = <$fh> ) or die "readline failed: $!";
2799 :                 open(my $fh, $arg) or warn "Can't open $arg: $!";
2803 :                         or die "readline failed for $arg: $!";
2810 :         Returns the value of a symbolic link, if symbolic links are implemented. If not, raises an exception. If there is a system error, returns the undefined value and sets $! (errno). If EXPR is omitted, uses $_.
2947 :                                  : "Can't locate $filename: $!\n";
2953 :                     $! = 0;
3083 :         Deletes the directory specified by FILENAME if that directory is empty. If it succeeds it returns true; otherwise it returns false and sets $! (errno). If FILENAME is omitted, uses $_.
3205 :         On error, "select" behaves just like select(2): it returns -1 and sets $!.
3233 :             die "Semaphore trouble: $!\n" unless semop($semid, $semop);
3307 :         Returns 1 for success; on error, returns "undef" if the first argument is not a valid filehandle, or returns 0 and sets $! for any other failure.
4151 :         Syscall returns whatever value returned by the system call it calls. If the system call fails, "syscall" returns -1 and sets $! (errno). Note that some system calls *can* legitimately return -1. The proper way to handle such calls is to assign "$!=0" before the call, then check the value of $! if "syscall" returns -1.
4183 :         Attempts to read LENGTH bytes of data into variable SCALAR from the specified FILEHANDLE, using the read(2). It bypasses buffered IO, so mixing this with other kinds of reads, "print", "write", "seek", "tell", or "eof" can cause confusion because the perlio or stdio layers usually buffers data. Returns the number of bytes actually read, 0 at end of file, or undef if there was an error (in the latter case $! is also set). SCALAR will be grown or shrunk so that the last byte actually read is the last byte of the scalar after the read.
4211 :         The return value is the exit status of the program as returned by the "wait" call. To get the actual exit value, shift right by eight (see below). See also "exec". This is *not* what you want to use to capture the output from a command; for that you should use merely backticks or "qx//", as described in "`STRING`" in perlop. Return value of -1 indicates a failure to start the program or an error of the wait(2) system call (inspect $! for the reason).
4226 :                 print "failed to execute: $!\n";
4247 :         Attempts to write LENGTH bytes of data from variable SCALAR to the specified FILEHANDLE, using write(2). If LENGTH is not specified, writes whole SCALAR. It bypasses buffered IO, so mixing this with reads (other than sysread()), "print", "write", "seek", "tell", or "eof" may cause confusion because the perlio and stdio layers usually buffer data. Returns the number of bytes actually written, or "undef" if there was an error (in this case the errno variable $! is also set). If the LENGTH is greater than the data available in the SCALAR after the OFFSET, only as much data as is available will be written.
4428 :         Deletes a list of files. On success, it returns the number of files it successfully deleted. On failure, it returns false and sets $! (errno):
4437 :                  unlink $file or warn "Could not unlink $file: $!";
4575 :                     || warn "couldn't touch $file: $!";
perlvar.pod
124 :             You can change both the real gid and the effective gid at the same time by using "POSIX::setgid()". Changes to $( require a check to $! to detect any possible errors after an attempted change.
134 :             You can change both the effective gid and the real gid at the same time by using "POSIX::setgid()" (use only a single numeric argument). Changes to $) require a check to $! to detect any possible errors after an attempted change.
142 :     $<      The real uid of this process. You can change both the real uid and the effective uid at the same time by using "POSIX::setuid()". Since changes to $< require a system call, check $! after a change attempt to detect any possible errors.
153 :             You can change both the effective uid and the real uid at the same time by using "POSIX::setuid()". Changes to $> require a check to $! to detect any possible errors after an attempted change.
637 :         open my $fh, "<", "foo" or die $!;
644 :         open my $fh, "<", "foo" or die $!;
654 :         open my $fh, "<", "foo" or die $!;
734 :                 open my $fh, "<", $myfile or die $!;
820 :     The variables $@, $!, $^E, and $? contain information about different types of error conditions that may appear during execution of a Perl program. The variables are shown ordered by the "distance" between the subsystem which reported the error and the Perl process. They correspond to errors detected by the Perl interpreter, C library, operating system, or an external program, respectively.
825 :             open my $pipe, "/cdrom/install |" or die $!;
827 :             close $pipe or die "bad pipe: $?, $!";
830 :     When perl executes the "eval()" expression, it translates the "open()", "<PIPE>", and "close" calls in the C run-time library and thence to the operating system kernel. perl sets $! to the C library's "errno" if one of these calls fails.
832 :     $@ is set if the string to be "eval"-ed did not compile (this may happen if "open" or "close" were imported with bad prototypes), or if Perl code executed during evaluation "die()"d. In these cases the value of $@ is the compile error, or the argument to "die" (which will interpolate $! and $?). (See also Fatal, though.)
834 :     Under a few operating systems, $^E may contain a more verbose error indicator, such as in this case, "CDROM tray not closed." Systems that do not support extended error messages leave $^E the same as $!.
836 :     Finally, $? may be set to non-0 value if the external program /cdrom/install fails. The upper eight bits reflect specific error conditions encountered by the program (the program's "exit()" value). The lower eight bits reflect mode of failure, like signal death and core dump information. See wait(2) for details. In contrast to $! and $^E, which are set only if error condition is detected, the variable $? is set on each "wait" or pipe "close", overwriting the old value. This is more like $@, which on every "eval()" is always set on failure and cleared on success.
838 :     For more details, see the individual descriptions at $@, $!, $^E, and $?.
848 :     $^E     Error information specific to the current operating system. At the moment, this differs from $! under only VMS, OS/2, and Win32 (and for MacPerl). On all other platforms, $^E is always just the same as $!.
850 :             Under VMS, $^E provides the VMS status value from the last system error. This is more specific information about the last system error than that provided by $!. This is particularly important when $! is set to EVMSERR.
854 :             Under Win32, $^E always returns the last error information reported by the Win32 call "GetLastError()" which describes the last error from within the Win32 API. Most Win32-specific code will report errors via $^E. ANSI C and Unix-like calls set "errno" and so most portable Perl code will report errors via $!.
856 :             Caveats mentioned in the description of $! generally apply to $^E, also.
891 :     $!      When referenced, $! retrieves the current value of the C "errno" integer variable. If $! is assigned a numerical value, that value is stored in "errno". When referenced as a string, $! yields the system error string corresponding to "errno".
893 :             Many system or library calls set "errno" if they fail, to indicate the cause of failure. They usually do not set "errno" to zero if they succeed. This means "errno", hence $!, is meaningful only *immediately* after a failure:
896 :                             # Here $! is meaningless.
900 :                             # ONLY here is $! meaningful.
902 :                             # Already here $! might be meaningless.
905 :                 # $! is meaningless.
907 :             Here, *meaningless* means that $! may be unrelated to the outcome of the "open()" operator. Assignment to $! is similarly ephemeral. It can be used immediately before invoking the "die()" operator, to set the exit value, or to inspect the system error string corresponding to error *n*, or to restore $! to a meaningful state.
915 :     %!      Each element of "%!" has a true value only if $! is set to that value. For example, $!{ENOENT} is true if and only if the current value of $! is "ENOENT"; that is, if the most recent error was "No such file or directory" (or its moral equivalent: not all operating systems give that exact error, and certainly not all languages). To check if a particular key is meaningful on your system, use "exists $!{the_key}"; for a list of legal keys, use "keys %!". See Errno for more information, and also see "$!".
perlopentut.pod
50 :             || die "$0: can't open $filename for reading: $!";
78 :         if ($!) {
79 :             die "unexpected error while reading from $filename: $!";
89 :             || die "$0: can't open $filename for reading: $!";
103 :             || die "$0: can't open $filename for appending: $!";
116 :             || die "$0: can't open $filename in write-open mode: $!";
134 :             || die "$0: can't open $filename for reading: $!";
137 :             || die "$0: can't open $filename for appending: $!";
140 :             || die "$0: can't open $filename in write-open mode: $!";
167 :             || die "$0: cannot open $name_in for reading: $!";
169 :             || die "$0: cannot open $name_out for writing: $!";
177 :                 die "couldn't write to $name_out: $!";
181 :         close($in_fh)       || die "couldn't close $name_in: $!";
182 :         close($out_fh)      || die "couldn't close $name_out: $!";
perltie.pod
53 :                     carp "Nice::Tie::Scalar got bad pid $pid: $!" if $^W;
70 :                 local($!) = 0;
72 :                 if ($!) { croak "getpriority failed: $!" }
102 :                     confess "setpriority failed: $!";
404 :                         || croak "@{[&whowasi]}: can't opendir $dir: $!";
457 :                 open(my $f, '>', $file) || croak "can't open $file: $!";
493 :                 carp "@{[&whowasi]}: can't unlink $file: $!" unless $success;
703 :                              or die "Cannot open $filename: $!\n";
perlop.pod
741 :         open HANDLE, "< :utf8", "filename" or die "Can't open: $!\n";
745 :         open(HANDLE, "< :utf8", "filename") or die "Can't open: $!\n";
749 :         open(HANDLE, "< :utf8", "filename") || die "Can't open: $!\n";
762 :         print FH $data              or die "Can't write to FH: $!";
1052 :                 || die "can't access /dev/tty: $!";
1332 :             open(SPLAT, "stuff")   || die "can't open stuff: $!";
1333 :             open(STDIN, "<&SPLAT") || die "can't dupe SPLAT: $!";
perlvms.pod
244 :         Note: Some sites have reported problems when using the file-access tests ("-r", "-w", and "-x") on files accessed via DEC's DFS. Specifically, since DFS does not currently provide access to the extended file header of files on remote volumes, attempts to examine the ACL fail, and the file tests will return false, with $! indicating that the file does not exist. You can use "stat" on these files, since that checks UIC-based protection only, and then manually check the appropriate bits, as defined by your C compiler's stat.h, in the mode value it returns, if you need an approximation of the file's protections.
269 :     die "die" will force the native VMS exit status to be an SS$_ABORT code if neither of the $! or $? status values are ones that would cause the native status to be interpreted as being what VMS classifies as SEVERE_ERROR severity for DCL error handling.
271 :         When "PERL_VMS_POSIX_EXIT" is active (see "$?" below), the native VMS exit status value will have either one of the $! or $? or $^E or the Unix value 255 encoded into it in a way that the effective original value can be decoded by other programs written in C, including Perl and the GNV package. As per the normal non-VMS behavior of "die" if either $! or $? are non-zero, one of those values will be encoded into a native VMS status value. If both of the Unix status values are 0, and the $^E value is set one of ERROR or SEVERE_ERROR severity, then the $^E value will be used as the exit code as is. If none of the above apply, the Unix value of 255 will be encoded into a native VMS exit status value.
405 :     $!  The string value of $! is that returned by the CRTL's strerror() function, so it will include the VMS message for VMS-specific errors. The numeric value of $! is the value of "errno", except if errno is EVMSERR, in which case $! contains the value of vaxc$errno. Setting $! always sets errno to the value specified. If this value is EVMSERR, it also sets vaxc$errno to 4 (NONAME-F-NOMSG), so that the string value of $! won't reflect the VMS error message from before $! was set.
407 :     $^E This variable provides direct access to VMS status values in vaxc$errno, which are often more specific than the generic Unix-style error messages in $!. Its numeric value is the value of vaxc$errno, and its string value is the corresponding VMS message string, as retrieved by sys$getmsg(). Setting $^E sets vaxc$errno to the value specified.
435 :         When the actual VMS termination status of the child is an error, internally the $! value will be set to the closest Unix errno value to that error so that Perl scripts that test for error messages will see the expected Unix style error message instead of a VMS message.
perllocale.pod
28 :         This is used by Perl itself only for accessing operating system error messages via $! and $^E.
73 :         *   The variables $! (and its synonyms $ERRNO and $OS_ERROR) and $^E (and its synonym $EXTENDED_OS_ERROR) when used as strings always are in terms of the current locale and as if within the scope of "use bytes". This is likely to change in Perl v5.22.
425 :     The remaining locale categories are not currently used by Perl itself. But again note that things Perl interacts with may use these, including extensions outside the standard Perl distribution, and by the operating system and its utilities. Note especially that the string value of $! and the error messages given by external utilities may be changed by "LC_MESSAGES". If you want to have portable error codes, use "%!". See Errno.
491 :                 or warn "Open of $tainted_output_file failed: $!\n";
502 :                 or warn "Open of $untainted_output_file failed: $!\n";
514 :                 or warn "Open of $localized_output_file failed: $!\n";
perlstyle.pod
49 :             open(FOO,$foo) || die "Can't open $foo: $!";
53 :             die "Can't open $foo: $!" unless open(FOO,$foo);
121 :             mkdir $tmpdir, 0700 or die "can't mkdir $tmpdir: $!";
122 :             chdir($tmpdir)      or die "can't chdir $tmpdir: $!";
123 :             mkdir 'tmp',   0777 or die "can't mkdir $tmpdir/tmp: $!";
127 :             opendir(D, $dir)     or die "can't opendir $dir: $!";
perlintro.pod
346 :      open(my $in,  "<",  "input.txt")  or die "Can't open input.txt: $!";
347 :      open(my $out, ">",  "output.txt") or die "Can't open output.txt: $!";
348 :      open(my $log, ">>", "my.log")     or die "Can't open my.log: $!";
371 :      close $in or die "$in: $!";
452 :         open my $logfile, ">>", "my.log" or die "Could not open my.log: $!";
perlsyn.pod
153 :         if (!open(FOO)) { die "Can't open $FOO: $!" }
154 :         die "Can't open $FOO: $!" unless open(FOO);
155 :         open(FOO)  || die "Can't open $FOO: $!";
156 :         open(FOO) ? () : die "Can't open $FOO: $!";
perlport.pod
182 :         open my $fh, '<', $existing_file) or die $!;
226 :     Don't count on specific values of $!, neither numeric nor especially the strings values. Users may switch their locales causing error messages to be translated into their languages. If you can trust a POSIXish environment, you can portably use the symbols defined by the Errno module, like ENOENT. And don't trust on the values of $! at all except immediately after a failed system call.
278 :             or die "cannot fork sendmail: $!";
352 :     Be careful in the tests you supply with your module or programs. Module code may be fully portable, but its tests might not be. This often happens when tests spawn off other processes or call external programs to aid in the testing, or when (as noted above) the tests assume certain things about the filesystem and paths. Be careful not to depend on a specific output style for errors, such as when checking $! after a failed system call. Using $! for anything else than displaying it as output is doubtful (though see the Errno module for testing reasonably portably for error value). Some platforms expect a certain output format, and Perl on those platforms may have been adjusted accordingly. Most specifically, don't anchor a regex when testing an error value.
perlpod.pod
304 :         open(X, ">>thing.dat") || die $!
309 :         C<<< open(X, ">>thing.dat") || die $! >>>
314 :         C<open(X, "E<gt>E<gt>thing.dat") || die $!>
perlobj.pod
121 :           open my $fh, '>', $self->path() or die $!;
122 :           print {$fh} $self->data()       or die $!;
123 :           close $fh                       or die $!;
perlsec.pod
43 :         open FOO, "/home/me/bar" or die $!;
159 :             die "Can't fork: $!" unless defined($pid = open(KID, "-|"));
181 :                     or die "can't exec myprog: $!";
perldbmfilter.pod
61 :           or die "Cannot open $filename: $!\n";
98 :             $DB_HASH or die "Cannot open $filename: $!\n";
perlrun.pod
248 :                  do { local $!; -f "$Config{sitelib}/sitecustomize.pl"; }
404 :                  print or die "-p destination: $!\n";
perlfilter.pod
182 :         open(IN, "<$in") or die "Cannot open file $in: $!\n";
183 :         open(OUT, ">$out") or die "Cannot open file $out: $!\n";
perldiag.pod
70 :             open(OUT,">$ARGV[0]") or die "Can't write to $ARGV[0]: $!";
611 :         (F) The first time the "%!" hash is used, perl automatically loads the Errno.pm module. The Errno module is expected to tie the %! hash to provide symbolic names for $! errno values.
perldata.pod
94 :     A sigil followed by a single character matching the "\p{POSIX_Punct}" property, like $! or "%+".
548 :                  or die "Can't open '@_': $!";
perlfork.pod
98 :                     die "fork() failed: $!" unless defined $pid;
127 :                     die "fork() failed: $!" unless defined $pid;
perlebcdic.pod
118 :      open(FH,"<perlebcdic.pod") or die "Could not open perlebcdic.pod: $!";
150 :      open(FH,"<perlebcdic.pod") or die "Could not open perlebcdic.pod: $!";
perlguts.pod
597 :     Some scalar variables contain more than one type of scalar data. For example, the variable $! contains either the numeric value of "errno" or its string equivalent from either "strerror" or "sys_errlist[]".
perlpodspec.pod
191 :             C<<< open(X, ">>thing.dat") || die $! >>>
perliol.pod
611 :     *   The handling of errors by the layer is not specified. e.g. when $! should be set explicitly, when the error handling should be just delegated to the top layer.
perlembed.pod
569 :             open FH, $filename or die "open '$filename' $!";
perlcheat.pod
65 :        5 gid    5 year-1900   5 wantarray   $!    sys/libcall error
perlsub.pod
767 :                 pipe    (READER,  WRITER)     or die "pipe: $!";
perldelta.pod
133 :         Due to an oversight, the value specified through -Dtargetsh to Configure would end up being ignored by some of the build process. This caused perls cross-compiled for Android to end up with defective versions of "system", "exec" and backticks: the commands would end up looking for /bin/sh instead of /system/bin/sh, and so would fail for the vast majority of devices, leaving $! as "ENOENT".
perlperf.pod
163 :         my $FH = FileHandle->new("< $file") or die("unable to open file($file): $!");
perlpacktut.pod
644 :             open( F, $path ) || die( "$path: cannot open ($!)\n" );
<< Back to Perldoc Search