If LAYER is present it is a single string, but may contain multiple
directives. The directives alter the behaviour of the file handle.
-When LAYER is present using binmode on text file makes sense.
+When LAYER is present using binmode on a text file makes sense.
If LAYER is omitted or specified as C<:raw> the filehandle is made
suitable for passing binary data. This includes turning off possible CRLF
determined.
If there is a syntax error or runtime error, or a C<die> statement is
-executed, an undefined value is returned by C<eval>, and C<$@> is set to the
+executed, C<eval> returns an undefined value in scalar context
+or an empty list in list context, and C<$@> is set to the
error message. If there was no error, C<$@> is guaranteed to be a null
string. Beware that using C<eval> neither silences perl from printing
warnings to STDERR, nor does it stuff the text of warning messages into C<$@>.
Given an expression that specifies a hash element or array element,
returns true if the specified element in the hash or array has ever
-been initialized, even if the corresponding value is undefined. The
-element is not autovivified if it doesn't exist.
+been initialized, even if the corresponding value is undefined.
print "Exists\n" if exists $hash{$key};
print "Defined\n" if defined $hash{$key};
Here's a mailbox appender for BSD systems.
- use Fcntl ':flock'; # import LOCK_* constants
+ use Fcntl qw(:flock SEEK_END); # import LOCK_* and SEEK_END constants
sub lock {
- flock(MBOX,LOCK_EX);
- # and, in case someone appended
- # while we were waiting...
- seek(MBOX, 0, 2);
+ my ($fh) = @_;
+ flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n";
+
+ # and, in case someone appended while we were waiting...
+ seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n";
}
sub unlock {
- flock(MBOX,LOCK_UN);
+ my ($fh) = @_;
+ flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n";
}
open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}")
or die "Can't open mailbox: $!";
- lock();
+ lock($mbox);
print $mbox $msg,"\n\n";
- unlock();
+ unlock($mbox);
On systems that support a real flock(), locks are inherited across fork()
calls, whereas those that must resort to the more capricious fcntl()
=item m//
-The match operator. See L<perlop>.
+The match operator. See L<perlop/"Regexp Quote-Like Operators">.
=item map BLOCK LIST
X<map>
=item s///
-The substitution operator. See L<perlop>.
+The substitution operator. See L<perlop/"Regexp Quote-Like Operators">.
=item say FILEHANDLE LIST
X<say>
If you had the entire header of a normal Unix email message in $header,
you could split it up into fields and their values this way:
- $header =~ s/\n\s+/ /g; # fix continuation lines
+ $header =~ s/\n(?=\s)//g; # fix continuation lines
%hdrs = (UNIX_FROM => split /^(\S*?):\s*/m, $header);
The pattern C</PATTERN/> may be replaced with an expression to specify
=item tr///
-The transliteration operator. Same as C<y///>. See L<perlop>.
+The transliteration operator. Same as C<y///>. See
+L<perlop/"Quote and Quote-like Operators">.
=item truncate FILEHANDLE,LENGTH
X<truncate>
Behaves like the wait(2) system call on your system: it waits for a child
process to terminate and returns the pid of the deceased process, or
C<-1> if there are no child processes. The status is returned in C<$?>
-and C<{^CHILD_ERROR_NATIVE}>.
+and C<${^CHILD_ERROR_NATIVE}>.
Note that a return value of C<-1> could mean that child processes are
being automatically reaped, as described in L<perlipc>.
Waits for a particular child process to terminate and returns the pid of
the deceased process, or C<-1> if there is no such child process. On some
systems, a value of 0 indicates that there are processes still running.
-The status is returned in C<$?> and C<{^CHILD_ERROR_NATIVE}>. If you say
+The status is returned in C<$?> and C<${^CHILD_ERROR_NATIVE}>. If you say
use POSIX ":sys_wait_h";
#...
=item y///
-The transliteration operator. Same as C<tr///>. See L<perlop>.
+The transliteration operator. Same as C<tr///>. See
+L<perlop/"Quote and Quote-like Operators">.
=back