A mechanism for inlineable OP equivalents of XSUBs is a TODO.
[p5sagit/p5-mst-13.2.git] / pod / perlfunc.pod
index 9cf780a..114d4da 100644 (file)
@@ -37,11 +37,11 @@ operator or unary operator, and precedence does matter.  And whitespace
 between the function and left parenthesis doesn't count--so you need to
 be careful sometimes:
 
-    print 1+2+4;       # Prints 7.
-    print(1+2) + 4;    # Prints 3.
-    print (1+2)+4;     # Also prints 3!
-    print +(1+2)+4;    # Prints 7.
-    print ((1+2)+4);   # Prints 7.
+    print 1+2+4;      # Prints 7.
+    print(1+2) + 4;   # Prints 3.
+    print (1+2)+4;    # Also prints 3!
+    print +(1+2)+4;   # Prints 7.
+    print ((1+2)+4);  # Prints 7.
 
 If you run Perl with the B<-w> switch it can warn you about this.  For
 example, the third line above produces:
@@ -86,6 +86,14 @@ which return C<-1> on failure.  Exceptions to this rule are C<wait>,
 C<waitpid>, and C<syscall>.  System calls also set the special C<$!>
 variable on failure.  Other functions do not, except accidentally.
 
+Extension modules can also hook into the Perl parser to define new
+kinds of keyword-headed expression.  These may look like functions, but
+may also look completely different.  The syntax following the keyword
+is defined entirely by the extension.  If you are an implementor, see
+L<perlapi/PL_keyword_plugin> for the mechanism.  If you are using such
+a module, see the module's documentation for details of the syntax that
+it defines.
+
 =head2 Perl Functions by Category
 X<function>
 
@@ -188,7 +196,7 @@ X<module>
 
 C<do>, C<import>, C<no>, C<package>, C<require>, C<use>
 
-=item Keywords related to classes and object-orientedness
+=item Keywords related to classes and object-orientation
 X<object> X<class> X<package>
 
 C<bless>, C<dbmclose>, C<dbmopen>, C<package>, C<ref>, C<tie>, C<tied>,
@@ -299,55 +307,57 @@ the undefined value if the file doesn't exist.  Despite the funny
 names, precedence is the same as any other named unary operator.  The
 operator may be any of:
 
-    -r File is readable by effective uid/gid.
-    -w File is writable by effective uid/gid.
-    -x File is executable by effective uid/gid.
-    -o File is owned by effective uid.
+    -r  File is readable by effective uid/gid.
+    -w  File is writable by effective uid/gid.
+    -x  File is executable by effective uid/gid.
+    -o  File is owned by effective uid.
 
-    -R File is readable by real uid/gid.
-    -W File is writable by real uid/gid.
-    -X File is executable by real uid/gid.
-    -O File is owned by real uid.
+    -R  File is readable by real uid/gid.
+    -W  File is writable by real uid/gid.
+    -X  File is executable by real uid/gid.
+    -O  File is owned by real uid.
 
-    -e File exists.
-    -z File has zero size (is empty).
-    -s File has nonzero size (returns size in bytes).
+    -e  File exists.
+    -z  File has zero size (is empty).
+    -s  File has nonzero size (returns size in bytes).
 
-    -f File is a plain file.
-    -d File is a directory.
-    -l File is a symbolic link.
-    -p File is a named pipe (FIFO), or Filehandle is a pipe.
-    -S File is a socket.
-    -b File is a block special file.
-    -c File is a character special file.
-    -t Filehandle is opened to a tty.
+    -f  File is a plain file.
+    -d  File is a directory.
+    -l  File is a symbolic link.
+    -p  File is a named pipe (FIFO), or Filehandle is a pipe.
+    -S  File is a socket.
+    -b  File is a block special file.
+    -c  File is a character special file.
+    -t  Filehandle is opened to a tty.
 
-    -u File has setuid bit set.
-    -g File has setgid bit set.
-    -k File has sticky bit set.
+    -u  File has setuid bit set.
+    -g  File has setgid bit set.
+    -k  File has sticky bit set.
 
-    -T File is an ASCII text file (heuristic guess).
-    -B File is a "binary" file (opposite of -T).
+    -T  File is an ASCII text file (heuristic guess).
+    -B  File is a "binary" file (opposite of -T).
 
-    -M Script start time minus file modification time, in days.
-    -A Same for access time.
-    -C Same for inode change time (Unix, may differ for other platforms)
+    -M  Script start time minus file modification time, in days.
+    -A  Same for access time.
+    -C  Same for inode change time (Unix, may differ for other platforms)
 
 Example:
 
     while (<>) {
-       chomp;
-       next unless -f $_;      # ignore specials
-       #...
+        chomp;
+        next unless -f $_;  # ignore specials
+        #...
     }
 
 The interpretation of the file permission operators C<-r>, C<-R>,
 C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode
 of the file and the uids and gids of the user.  There may be other
-reasons you can't actually read, write, or execute the file.  Such
-reasons may be for example network filesystem access controls, ACLs
-(access control lists), read-only filesystems, and unrecognized
-executable formats.
+reasons you can't actually read, write, or execute the file: for
+example network filesystem access controls, ACLs (access control lists),
+read-only filesystems, and unrecognized executable formats.  Note
+that the use of these six specific operators to verify if some operation
+is possible is usually a mistake, because it may be open to race
+conditions.
 
 Also note that, for the superuser on the local filesystems, the C<-r>,
 C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1
@@ -362,8 +372,11 @@ will test whether the permission can (not) be granted using the
 access() family of system calls.  Also note that the C<-x> and C<-X> may
 under this pragma return true even if there are no execute permission
 bits set (nor any extra execute permission ACLs).  This strangeness is
-due to the underlying system calls' definitions.  Read the
-documentation for the C<filetest> pragma for more information.
+due to the underlying system calls' definitions. Note also that, due to
+the implementation of C<use filetest 'access'>, the C<_> special
+filehandle won't cache the results of the file tests when this pragma is
+in effect.  Read the documentation for the C<filetest> pragma for more
+information.
 
 Note that C<-s/a/b/> does not do a negated substitution.  Saying
 C<-exp($foo)> still works as expected, however--only single letters
@@ -445,12 +458,12 @@ previous timer, and an argument of C<0> may be supplied to cancel the
 previous timer without starting a new one.  The returned value is the
 amount of time remaining on the previous timer.
 
-For delays of finer granularity than one second, you may use Perl's
-four-argument version of select() leaving the first three arguments
-undefined, or you might be able to use the C<syscall> interface to
-access setitimer(2) if your system supports it.  The Time::HiRes
-module (from CPAN, and starting from Perl 5.8 part of the standard
-distribution) may also prove useful.
+For delays of finer granularity than one second, the Time::HiRes module
+(from CPAN, and starting from Perl 5.8 part of the standard
+distribution) provides ualarm().  You may also use Perl's four-argument
+version of select() leaving the first three arguments undefined, or you
+might be able to use the C<syscall> interface to access setitimer(2) if
+your system supports it. See L<perlfaq8> for details.
 
 It is usually a mistake to intermix C<alarm> and C<sleep> calls.
 (C<sleep> may be internally implemented in your system with C<alarm>)
@@ -462,17 +475,17 @@ restart system calls on some systems.  Using C<eval>/C<die> always works,
 modulo the caveats given in L<perlipc/"Signals">.
 
     eval {
-       local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
-       alarm $timeout;
-       $nread = sysread SOCKET, $buffer, $size;
-       alarm 0;
+        local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
+        alarm $timeout;
+        $nread = sysread SOCKET, $buffer, $size;
+        alarm 0;
     };
     if ($@) {
-       die unless $@ eq "alarm\n";   # propagate unexpected errors
-       # timed out
+        die unless $@ eq "alarm\n";   # propagate unexpected errors
+        # timed out
     }
     else {
-       # didn't
+        # didn't
     }
 
 For more information see L<perlipc>.
@@ -487,7 +500,8 @@ function, or use the familiar relation:
 
     sub tan { sin($_[0]) / cos($_[0])  }
 
-Note that atan2(0, 0) is not well-defined.
+The return value for C<atan2(0,0)> is implementation-defined; consult
+your atan2(3) manpage for more information.
 
 =item bind SOCKET,NAME
 X<bind>
@@ -519,7 +533,7 @@ like for example images.
 
 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
@@ -644,7 +658,7 @@ call, but an C<eval>.  In such a case additional elements $evaltext and
 C<$is_require> are set: C<$is_require> is true if the frame is created by a
 C<require> or C<use> statement, $evaltext contains the text of the
 C<eval EXPR> statement.  In particular, for an C<eval BLOCK> statement,
-$filename is C<(eval)>, but $evaltext is undefined.  (Note also that
+$subroutine is C<(eval)>, but $evaltext is undefined.  (Note also that
 each C<use> statement creates a C<require> frame inside an C<eval EXPR>
 frame.)  $subroutine may also be C<(unknown)> if this particular
 subroutine happens to have been deleted from the symbol table.
@@ -743,9 +757,9 @@ remove anything.
 If VARIABLE is omitted, it chomps C<$_>.  Example:
 
     while (<>) {
-       chomp;  # avoid \n on last field
-       @array = split(/:/);
-       # ...
+        chomp;  # avoid \n on last field
+        @array = split(/:/);
+        # ...
     }
 
 If VARIABLE is a hash, it chomps the hash's values, but not its keys.
@@ -813,9 +827,9 @@ Here's an example that looks up nonnumeric uids in the passwd file:
     chomp($pattern = <STDIN>);
 
     ($login,$pass,$uid,$gid) = getpwnam($user)
-       or die "$user not in passwd file";
+        or die "$user not in passwd file";
 
-    @ary = glob($pattern);     # expand filenames
+    @ary = glob($pattern);  # expand filenames
     chown $uid, $gid, @ary;
 
 On most systems, you are not allowed to change the ownership of the
@@ -895,11 +909,11 @@ Example:
 
     open(OUTPUT, '|sort >foo')  # pipe to sort
         or die "Can't start sort: $!";
-    #...                       # print stuff to output
-    close OUTPUT               # wait for sort to finish
+    #...                        # print stuff to output
+    close OUTPUT                # wait for sort to finish
         or warn $! ? "Error closing sort pipe: $!"
                    : "Exit status $? from sort";
-    open(INPUT, 'foo')         # get sort's results
+    open(INPUT, 'foo')          # get sort's results
         or die "Can't open 'foo' for input: $!";
 
 FILEHANDLE may be an expression whose value can be used as an indirect
@@ -938,12 +952,12 @@ the main block.  So will C<next>, but since it will execute a C<continue>
 block, it may be more entertaining.
 
     while (EXPR) {
-       ### redo always comes here
-       do_something;
+        ### redo always comes here
+        do_something;
     } continue {
-       ### next always comes here
-       do_something_else;
-       # then back the top to re-check EXPR
+        ### next always comes here
+        do_something_else;
+        # then back the top to re-check EXPR
     }
     ### last always comes here
 
@@ -976,7 +990,7 @@ X<decrypt> X<cryptography> X<passwd> X<encrypt>
 
 Creates a digest string exactly like the crypt(3) function in the C
 library (assuming that you actually have a version there that has not
-been extirpated as a potential munitions).
+been extirpated as a potential munition).
 
 crypt() is a one-way hash function.  The PLAINTEXT and SALT is turned
 into a short string, called a digest, which is returned.  The same
@@ -1006,7 +1020,7 @@ digest matter.
 
 Traditionally the result is a string of 13 bytes: two first bytes of
 the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only
-the first eight bytes of the digest string mattered, but alternative
+the first eight bytes of PLAINTEXT mattered. But alternative
 hashing schemes (like MD5), higher level security schemes (like C2),
 and implementations on non-UNIX platforms may produce different
 strings.
@@ -1030,9 +1044,9 @@ their password:
     system "stty echo";
 
     if (crypt($word, $pwd) ne $pwd) {
-       die "Sorry...\n";
+        die "Sorry...\n";
     } else {
-       print "ok\n";
+        print "ok\n";
     }
 
 Of course, typing in your own password to whoever asks you
@@ -1084,7 +1098,7 @@ function to iterate over large DBM files.  Example:
     # print out history file offsets
     dbmopen(%HIST,'/usr/lib/news/history',0666);
     while (($key,$val) = each %HIST) {
-       print $key, ' = ', unpack('L',$val), "\n";
+        print $key, ' = ', unpack('L',$val), "\n";
     }
     dbmclose(%HIST);
 
@@ -1097,7 +1111,7 @@ before you call dbmopen():
 
     use DB_File;
     dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db")
-       or die "Can't open netscape history file: $!";
+        or die "Can't open netscape history file: $!";
 
 =item defined EXPR
 X<defined> X<undef> X<undefined>
@@ -1142,7 +1156,7 @@ Examples:
     print if defined $switch{'D'};
     print "$val\n" while defined($val = pop(@ary));
     die "Can't readlink $sym: $!"
-       unless defined($value = readlink $sym);
+        unless defined($value = readlink $sym);
     sub foo { defined &$bar ? &$bar(@_) : die "No bar"; }
     $debugging = 0 unless defined $debugging;
 
@@ -1196,11 +1210,11 @@ after them down.  Use splice() for that.  See L</exists>.
 The following (inefficiently) deletes all the values of %HASH and @ARRAY:
 
     foreach $key (keys %HASH) {
-       delete $HASH{$key};
+        delete $HASH{$key};
     }
 
     foreach $index (0 .. $#ARRAY) {
-       delete $ARRAY[$index];
+        delete $ARRAY[$index];
     }
 
 And so do these:
@@ -1212,11 +1226,11 @@ And so do these:
 But both of these are slower than just assigning the empty list
 or undefining %HASH or @ARRAY:
 
-    %HASH = ();                # completely empty %HASH
-    undef %HASH;       # forget %HASH ever existed
+    %HASH = ();     # completely empty %HASH
+    undef %HASH;    # forget %HASH ever existed
 
-    @ARRAY = ();       # completely empty @ARRAY
-    undef @ARRAY;      # forget @ARRAY ever existed
+    @ARRAY = ();    # completely empty @ARRAY
+    undef @ARRAY;   # forget @ARRAY ever existed
 
 Note that the EXPR can be arbitrarily complicated as long as the final
 operation is a hash element, array element,  hash slice, or array slice
@@ -1228,6 +1242,10 @@ lookup:
     delete $ref->[$x][$y][$index];
     delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices];
 
+The C<delete local EXPR> construct can also be used to localize the deletion
+of array/hash elements to the current block.
+See L<perlsub/"Localized deletion of elements of composite types">.
+
 =item die LIST
 X<die> X<throw> X<exception> X<raise> X<$@> X<abort>
 
@@ -1265,14 +1283,14 @@ produce, respectively
 
 See also exit(), warn(), and the Carp module.
 
-If LIST is empty and C<$@> already contains a value (typically from a
+If the output is empty and C<$@> already contains a value (typically from a
 previous eval) that value is reused after appending C<"\t...propagated">.
 This is useful for propagating exceptions:
 
     eval { ... };
     die unless $@ =~ /Expected exception/;
 
-If LIST is empty and C<$@> contains an object reference that has a
+If the output is empty and C<$@> contains an object reference that has a
 C<PROPAGATE> method, that method will be called with additional file
 and line number parameters.  The return value replaces the value in
 C<$@>.  i.e. as if C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >>
@@ -1318,7 +1336,7 @@ currently the case--the C<$SIG{__DIE__}> hook is currently called
 even inside eval()ed blocks/strings!  If one wants the hook to do
 nothing in such situations, put
 
-       die @_ if $^S;
+    die @_ if $^S;
 
 as the first line of the handler (see L<perlvar/$^S>).  Because
 this promotes strange action at a distance, this counterintuitive
@@ -1378,12 +1396,12 @@ file.  Manual error checking can be done this way:
     # read in config files: system first, then user
     for $file ("/share/prog/defaults.rc",
                "$ENV{HOME}/.someprogrc")
-   {
-       unless ($return = do $file) {
-           warn "couldn't parse $file: $@" if $@;
-           warn "couldn't do $file: $!"    unless defined $return;
-           warn "couldn't run $file"       unless $return;
-       }
+    {
+        unless ($return = do $file) {
+            warn "couldn't parse $file: $@" if $@;
+            warn "couldn't do $file: $!"    unless defined $return;
+            warn "couldn't run $file"       unless $return;
+        }
     }
 
 =item dump LABEL
@@ -1413,25 +1431,30 @@ typo.
 =item each HASH
 X<each> X<hash, iterator>
 
+=item each ARRAY
+X<array, iterator>
+
 When called in list context, returns a 2-element list consisting of the
-key and value for the next element of a hash, so that you can iterate over
-it.  When called in scalar context, returns only the key for the next
-element in the hash.
+key and value for the next element of a hash, or the index and value for
+the next element of an array, so that you can iterate over it.  When called
+in scalar context, returns only the key for the next element in the hash
+(or the index for an array).
 
-Entries are returned in an apparently random order.  The actual random
+Hash entries are returned in an apparently random order.  The actual random
 order is subject to change in future versions of perl, but it is
 guaranteed to be in the same order as either the C<keys> or C<values>
 function would produce on the same (unmodified) hash.  Since Perl
-5.8.1 the ordering is different even between different runs of Perl
+5.8.2 the ordering can be different even between different runs of Perl
 for security reasons (see L<perlsec/"Algorithmic Complexity Attacks">).
 
-When the hash is entirely read, a null array is returned in list context
-(which when assigned produces a false (C<0>) value), and C<undef> in
+When the hash or array is entirely read, a null array is returned in list
+context (which when assigned produces a false (C<0>) value), and C<undef> in
 scalar context.  The next call to C<each> after that will start iterating
-again.  There is a single iterator for each hash, shared by all C<each>,
-C<keys>, and C<values> function calls in the program; it can be reset by
-reading all the elements from the hash, or by evaluating C<keys HASH> or
-C<values HASH>.  If you add or delete elements of a hash while you're
+again.  There is a single iterator for each hash or array, shared by all
+C<each>, C<keys>, and C<values> function calls in the program; it can be
+reset by reading all the elements from the hash or array, or by evaluating
+C<keys HASH>, C<values HASH>, C<keys ARRAY>, or C<values ARRAY>.  If you add
+or delete elements of a hash while you're
 iterating over it, you may get entries skipped or duplicated, so
 don't.  Exception: It is always safe to delete the item most recently
 returned by C<each()>, which means that the following code will work:
@@ -1445,7 +1468,7 @@ The following prints out your environment like the printenv(1) program,
 only in a different order:
 
     while (($key,$value) = each %ENV) {
-       print "$key=$value\n";
+        print "$key=$value\n";
     }
 
 See also C<keys>, C<values> and C<sort>.
@@ -1484,19 +1507,19 @@ last file.  Examples:
 
     # reset line numbering on each input file
     while (<>) {
-       next if /^\s*#/;        # skip comments
-       print "$.\t$_";
+        next if /^\s*#/;  # skip comments
+        print "$.\t$_";
     } continue {
-       close ARGV  if eof;     # Not eof()!
+        close ARGV if eof;  # Not eof()!
     }
 
     # insert dashes just before last line of last file
     while (<>) {
-       if (eof()) {            # check for end of last file
-           print "--------------\n";
-       }
-       print;
-       last if eof();          # needed if we're reading from a terminal
+        if (eof()) {  # check for end of last file
+            print "--------------\n";
+        }
+        print;
+        last if eof();          # needed if we're reading from a terminal
     }
 
 Practical hint: you almost never need to use C<eof> in Perl, because the
@@ -1538,7 +1561,8 @@ itself.  See L</wantarray> for more on how the evaluation context can be
 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<$@>.
@@ -1551,6 +1575,10 @@ determining whether a particular feature (such as C<socket> or C<symlink>)
 is implemented.  It is also Perl's exception trapping mechanism, where
 the die operator is used to raise exceptions.
 
+If you want to trap errors when loading an XS module, some problems with
+the binary interface (such as Perl version skew) may be fatal even with
+C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See L<perlrun>.
+
 If the code to be executed doesn't vary, you may use the eval-BLOCK
 form to trap run-time errors without incurring the penalty of
 recompiling each time.  The error, if any, is still returned in C<$@>.
@@ -1563,10 +1591,10 @@ Examples:
     eval '$answer = $a / $b'; warn $@ if $@;
 
     # a compile-time error
-    eval { $answer = };                        # WRONG
+    eval { $answer = }; # WRONG
 
     # a run-time error
-    eval '$answer =';  # sets $@
+    eval '$answer =';   # sets $@
 
 Using the C<eval{}> form as an exception trap in libraries does have some
 issues.  Due to the current arguably broken state of C<__DIE__> hooks, you
@@ -1595,14 +1623,14 @@ may be fixed in a future release.
 With an C<eval>, you should be especially careful to remember what's
 being looked at when:
 
-    eval $x;           # CASE 1
-    eval "$x";         # CASE 2
+    eval $x;        # CASE 1
+    eval "$x";      # CASE 2
 
-    eval '$x';         # CASE 3
-    eval { $x };       # CASE 4
+    eval '$x';      # CASE 3
+    eval { $x };    # CASE 4
 
-    eval "\$$x++";     # CASE 5
-    $$x++;             # CASE 6
+    eval "\$$x++";  # CASE 5
+    $$x++;          # CASE 6
 
 Cases 1 and 2 above behave identically: they run the code contained in
 the variable $x.  (Although case 2 has misleading double quotes making
@@ -1615,6 +1643,22 @@ normally you I<would> like to use double quotes, except that in this
 particular situation, you can just use symbolic references instead, as
 in case 6.
 
+The assignment to C<$@> occurs before restoration of localised variables,
+which means a temporary is required if you want to mask some but not all
+errors:
+
+    # alter $@ on nefarious repugnancy only
+    {
+       my $e;
+       {
+          local $@; # protect existing $@
+          eval { test_repugnancy() };
+          # $@ =~ /nefarious/ and die $@; # DOES NOT WORK
+          $@ =~ /nefarious/ and $e = $@;
+       }
+       die $e if defined $e
+    }
+
 C<eval BLOCK> does I<not> count as a loop, so the loop control statements
 C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
 
@@ -1663,11 +1707,11 @@ LIST as a multivalued list, even if there is only a single scalar in
 the list.)  Example:
 
     $shell = '/bin/csh';
-    exec $shell '-sh';         # pretend it's a login shell
+    exec $shell '-sh';    # pretend it's a login shell
 
 or, more directly,
 
-    exec {'/bin/csh'} '-sh';   # pretend it's a login shell
+    exec {'/bin/csh'} '-sh';  # pretend it's a login shell
 
 When the arguments get executed via the system shell, results will
 be subject to its quirks and capabilities.  See L<perlop/"`STRING`">
@@ -1704,15 +1748,14 @@ X<exists> X<autovivification>
 
 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};
+    print "Exists\n"    if exists $hash{$key};
+    print "Defined\n"   if defined $hash{$key};
     print "True\n"      if $hash{$key};
 
-    print "Exists\n"   if exists $array[$index];
-    print "Defined\n"  if defined $array[$index];
+    print "Exists\n"    if exists $array[$index];
+    print "Defined\n"   if defined $array[$index];
     print "True\n"      if $array[$index];
 
 A hash or array element can be true only if it's defined, and defined if
@@ -1726,17 +1769,17 @@ exist may still be callable: its package may have an C<AUTOLOAD>
 method that makes it spring into existence the first time that it is
 called -- see L<perlsub>.
 
-    print "Exists\n"   if exists &subroutine;
-    print "Defined\n"  if defined &subroutine;
+    print "Exists\n"  if exists &subroutine;
+    print "Defined\n" if defined &subroutine;
 
 Note that the EXPR can be arbitrarily complicated as long as the final
 operation is a hash or array key lookup or subroutine name:
 
-    if (exists $ref->{A}->{B}->{$key})         { }
-    if (exists $hash{A}{B}{$key})      { }
+    if (exists $ref->{A}->{B}->{$key})  { }
+    if (exists $hash{A}{B}{$key})       { }
 
-    if (exists $ref->{A}->{B}->[$ix])  { }
-    if (exists $hash{A}{B}[$ix])       { }
+    if (exists $ref->{A}->{B}->[$ix])   { }
+    if (exists $hash{A}{B}[$ix])        { }
 
     if (exists &{$ref->{A}{B}{$key}})   { }
 
@@ -1747,8 +1790,8 @@ into existence due to the existence test for the $key element above.
 This happens anywhere the arrow operator is used, including even:
 
     undef $ref;
-    if (exists $ref->{"Some key"})     { }
-    print $ref;            # prints HASH(0x80d3d5c)
+    if (exists $ref->{"Some key"})    { }
+    print $ref;  # prints HASH(0x80d3d5c)
 
 This surprising autovivification in what does not at first--or even
 second--glance appear to be an lvalue context may be fixed in a future
@@ -1757,8 +1800,8 @@ release.
 Use of a subroutine call, rather than a subroutine name, as an argument
 to exists() is an error.
 
-    exists &sub;       # OK
-    exists &sub();     # Error
+    exists &sub;    # OK
+    exists &sub();  # Error
 
 =item exit EXPR
 X<exit> X<terminate> X<abort>
@@ -1809,7 +1852,7 @@ For example:
 
     use Fcntl;
     fcntl($filehandle, F_GETFL, $packed_return_buffer)
-       or die "can't fcntl F_GETFL: $!";
+        or die "can't fcntl F_GETFL: $!";
 
 You don't have to check for C<defined> on the return from C<fcntl>.
 Like C<ioctl>, it maps a C<0> return from the system call into
@@ -1846,7 +1889,7 @@ You can use this to find out whether two handles refer to the
 same underlying descriptor:
 
     if (fileno(THIS) == fileno(THAT)) {
-       print "THIS and THAT are dups\n";
+        print "THIS and THAT are dups\n";
     }
 
 (Filehandles connected to memory objects via new features of C<open> may
@@ -1905,25 +1948,27 @@ perl.
 
 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(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
-           or die "Can't open mailbox: $!";
+    open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}")
+        or die "Can't open mailbox: $!";
 
-    lock();
-    print MBOX $msg,"\n\n";
-    unlock();
+    lock($mbox);
+    print $mbox $msg,"\n\n";
+    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()
@@ -1967,8 +2012,8 @@ Declare a picture format for use by the C<write> function.  For
 example:
 
     format Something =
-       Test: @<<<<<<<< @||||| @>>>>>
-             $str,     $%,    '$' . int($num)
+        Test: @<<<<<<<< @||||| @>>>>>
+              $str,     $%,    '$' . int($num)
     .
 
     $str = "widget";
@@ -2011,19 +2056,19 @@ used by itself to fetch single characters without waiting for the user
 to hit enter.  For that, try something more like:
 
     if ($BSD_STYLE) {
-       system "stty cbreak </dev/tty >/dev/tty 2>&1";
+        system "stty cbreak </dev/tty >/dev/tty 2>&1";
     }
     else {
-       system "stty", '-icanon', 'eol', "\001";
+        system "stty", '-icanon', 'eol', "\001";
     }
 
     $key = getc(STDIN);
 
     if ($BSD_STYLE) {
-       system "stty -cbreak </dev/tty >/dev/tty 2>&1";
+        system "stty -cbreak </dev/tty >/dev/tty 2>&1";
     }
     else {
-       system "stty", 'icanon', 'eol', '^@'; # ASCII null
+        system "stty", 'icanon', 'eol', '^@'; # ASCII null
     }
     print "\n";
 
@@ -2084,7 +2129,7 @@ C<Linux::Pid>.
 X<getpriority> X<priority> X<nice>
 
 Returns the current priority for a process, a process group, or a user.
-(See L<getpriority(2)>.)  Will raise a fatal exception if used on a
+(See C<getpriority(2)>.)  Will raise a fatal exception if used on a
 machine that doesn't implement getpriority(2).
 
 =item getpwnam NAME
@@ -2230,6 +2275,18 @@ The Socket library makes this slightly easier:
     # or going the other way
     $straddr = inet_ntoa($iaddr);
 
+In the opposite way, to resolve a hostname to the IP address
+you can write this:
+
+    use Socket;
+    $packed_ip = gethostbyname("www.perl.org");
+    if (defined $packed_ip) {
+        $ip_address = inet_ntoa($packed_ip);
+    }
+
+Make sure <gethostbyname()> is called in SCALAR context and that
+its return value is checked for definedness.
+
 If you get tired of remembering which element of the return list
 contains which return value, by-name interfaces are provided
 in standard modules: C<File::stat>, C<Net::hostent>, C<Net::netent>,
@@ -2284,10 +2341,10 @@ An example testing if Nagle's algorithm is turned on on a socket:
     use Socket qw(:all);
 
     defined(my $tcp = getprotobyname("tcp"))
-       or die "Could not determine the protocol number for tcp";
+        or die "Could not determine the protocol number for tcp";
     # my $tcp = IPPROTO_TCP; # Alternative
     my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
-       or die "Could not query TCP_NODELAY socket option: $!";
+        or die "Could not query TCP_NODELAY socket option: $!";
     my $nodelay = unpack("I", $packed);
     print "Nagle's algorithm is turned ", $nodelay ? "off\n" : "on\n";
 
@@ -2305,8 +2362,14 @@ implementing the C<< <*.c> >> operator, but you can use it directly. If
 EXPR is omitted, C<$_> is used.  The C<< <*.c> >> operator is discussed in
 more detail in L<perlop/"I/O Operators">.
 
+Note that C<glob> will split its arguments on whitespace, treating
+each segment as separate pattern.  As such, C<glob('*.c *.h')> would
+match all files with a F<.c> or F<.h> extension.  The expression
+C<glob('.* *')> would match all files in the current working directory.
+
 Beginning with v5.6.0, this operator is implemented using the standard
-C<File::Glob> extension.  See L<File::Glob> for details.
+C<File::Glob> extension.  See L<File::Glob> for details, including
+C<bsd_glob> which does not treat whitespace as a pattern separator.
 
 =item gmtime EXPR
 X<gmtime> X<UTC> X<Greenwich>
@@ -2329,18 +2392,15 @@ X<goto> X<jump> X<jmp>
 
 =item goto &NAME
 
-The C<goto-LABEL> form finds the statement labeled with LABEL and resumes
-execution there.  It may not be used to go into any construct that
-requires initialization, such as a subroutine or a C<foreach> loop.  It
-also can't be used to go into a construct that is optimized away,
-or to get out of a block or subroutine given to C<sort>.
-It can be used to go almost anywhere else within the dynamic scope,
-including out of subroutines, but it's usually better to use some other
-construct such as C<last> or C<die>.  The author of Perl has never felt the
-need to use this form of C<goto> (in Perl, that is--C is another matter).
-(The difference being that C does not offer named loops combined with
-loop control.  Perl does, and this replaces most structured uses of C<goto>
-in other languages.)
+The C<goto-LABEL> form finds the statement labeled with LABEL and
+resumes execution there. It can't be used to get out of a block or
+subroutine given to C<sort>.  It can be used to go almost anywhere
+else within the dynamic scope, including out of subroutines, but it's
+usually better to use some other construct such as C<last> or C<die>.
+The author of Perl has never felt the need to use this form of C<goto>
+(in Perl, that is--C is another matter).  (The difference being that C
+does not offer named loops combined with loop control.  Perl does, and
+this replaces most structured uses of C<goto> in other languages.)
 
 The C<goto-EXPR> form expects a label name, whose scope will be resolved
 dynamically.  This allows for computed C<goto>s per FORTRAN, but isn't
@@ -2348,6 +2408,12 @@ necessarily recommended if you're optimizing for maintainability:
 
     goto ("FOO", "BAR", "GLARCH")[$i];
 
+Use of C<goto-LABEL> or C<goto-EXPR> to jump into a construct is
+deprecated and will issue a warning.  Even then, it may not be used to
+go into any construct that requires initialization, such as a
+subroutine or a C<foreach> loop.  It also can't be used to go into a
+construct that is optimized away.
+
 The C<goto-&NAME> form is quite different from the other forms of
 C<goto>.  In fact, it isn't a goto in the normal sense at all, and
 doesn't have the stigma associated with other gotos.  Instead, it
@@ -2458,7 +2524,7 @@ X<ioctl>
 
 Implements the ioctl(2) function.  You'll probably first have to say
 
-    require "sys/ioctl.ph";    # probably in $Config{archlib}/sys/ioctl.ph
+    require "sys/ioctl.ph";  # probably in $Config{archlib}/sys/ioctl.ph
 
 to get the correct function definitions.  If F<sys/ioctl.ph> doesn't
 exist or doesn't have the correct definitions you'll have to roll your
@@ -2475,10 +2541,10 @@ C<ioctl>.
 
 The return value of C<ioctl> (and C<fcntl>) is as follows:
 
-       if OS returns:          then Perl returns:
-           -1                    undefined value
-            0                  string "0 but true"
-       anything else               that number
+    if OS returns:      then Perl returns:
+        -1               undefined value
+         0              string "0 but true"
+    anything else           that number
 
 Thus Perl returns true on success and false on failure, yet you can
 still easily determine the actual value returned by the operating
@@ -2504,10 +2570,12 @@ first argument.  Compare L</split>.
 =item keys HASH
 X<keys> X<key>
 
-Returns a list consisting of all the keys of the named hash.
-(In scalar context, returns the number of keys.)
+=item keys ARRAY
 
-The keys are returned in an apparently random order.  The actual
+Returns a list consisting of all the keys of the named hash, or the indices
+of an array. (In scalar context, returns the number of keys or indices.)
+
+The keys of a hash are returned in an apparently random order.  The actual
 random order is subject to change in future versions of perl, but it
 is guaranteed to be the same order as either the C<values> or C<each>
 function produces (given that the hash has not been modified).  Since
@@ -2515,7 +2583,7 @@ Perl 5.8.1 the ordering is different even between different runs of
 Perl for security reasons (see L<perlsec/"Algorithmic Complexity
 Attacks">).
 
-As a side effect, calling keys() resets the HASH's internal iterator
+As a side effect, calling keys() resets the HASH or ARRAY's internal iterator
 (see L</each>).  In particular, calling keys() in void context resets
 the iterator with no other overhead.
 
@@ -2524,13 +2592,13 @@ Here is yet another way to print your environment:
     @keys = keys %ENV;
     @values = values %ENV;
     while (@keys) {
-       print pop(@keys), '=', pop(@values), "\n";
+        print pop(@keys), '=', pop(@values), "\n";
     }
 
 or how about sorted by key:
 
     foreach $key (sort(keys %ENV)) {
-       print $key, '=', $ENV{$key}, "\n";
+        print $key, '=', $ENV{$key}, "\n";
     }
 
 The returned values are copies of the original keys in the hash, so
@@ -2540,7 +2608,7 @@ To sort a hash by value, you'll need to use a C<sort> function.
 Here's a descending numeric sort of a hash by its values:
 
     foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
-       printf "%4d %s\n", $hash{$key}, $key;
+        printf "%4d %s\n", $hash{$key}, $key;
     }
 
 As an lvalue C<keys> allows you to increase the number of hash buckets
@@ -2556,7 +2624,8 @@ buckets will be retained even if you do C<%hash = ()>, use C<undef
 %hash> if you want to free the storage while C<%hash> is still in scope.
 You can't shrink the number of buckets allocated for the hash using
 C<keys> in this way (but you needn't worry about doing this by accident,
-as trying has no effect).
+as trying has no effect). C<keys @array> in an lvalue context is a syntax
+error.
 
 See also C<each>, C<values> and C<sort>.
 
@@ -2577,11 +2646,13 @@ the super-user).  This is a useful way to check that a child process is
 alive (even if only as a zombie) and hasn't changed its UID.  See
 L<perlport> for notes on the portability of this construct.
 
-Unlike in the shell, if SIGNAL is negative, it kills
-process groups instead of processes.  (On System V, a negative I<PROCESS>
-number will also kill process groups, but that's not portable.)  That
-means you usually want to use positive not negative signals.  You may also
-use a signal name in quotes.
+Unlike in the shell, if SIGNAL is negative, it kills process groups instead
+of processes. That means you usually want to use positive not negative signals.
+You may also use a signal name in quotes.
+
+The behavior of kill when a I<PROCESS> number is zero or negative depends on
+the operating system.  For example, on POSIX-conforming systems, zero will
+signal the current process group and -1 will signal all processes.
 
 See L<perlipc/"Signals"> for more details.
 
@@ -2596,8 +2667,8 @@ omitted, the command refers to the innermost enclosing loop.  The
 C<continue> block, if any, is not executed:
 
     LINE: while (<STDIN>) {
-       last LINE if /^$/;      # exit when done with header
-       #...
+        last LINE if /^$/;  # exit when done with header
+        #...
     }
 
 C<last> cannot be used to exit a block which returns a value such as
@@ -2617,12 +2688,61 @@ X<lc> X<lowercase>
 =item lc
 
 Returns a lowercased version of EXPR.  This is the internal function
-implementing the C<\L> escape in double-quoted strings.  Respects
-current LC_CTYPE locale if C<use locale> in force.  See L<perllocale>
-and L<perlunicode> for more details about locale and Unicode support.
+implementing the C<\L> escape in double-quoted strings.
 
 If EXPR is omitted, uses C<$_>.
 
+What gets returned depends on several factors:
+
+=over
+
+=item If C<use bytes> is in effect:
+
+=over
+
+=item On EBCDIC platforms
+
+The results are what the C language system call C<tolower()> returns.
+
+=item On ASCII platforms
+
+The results follow ASCII semantics.  Only characters C<A-Z> change, to C<a-z>
+respectively.
+
+=back
+
+=item Otherwise, If EXPR has the UTF8 flag set
+
+If the current package has a subroutine named C<ToLower>, it will be used to
+change the case (See L<perlunicode/User-Defined Case Mappings>.)
+Otherwise Unicode semantics are used for the case change.
+
+=item Otherwise, if C<use locale> is in effect
+
+Respects current LC_CTYPE locale.  See L<perllocale>.
+
+=item Otherwise, if C<use feature 'unicode_strings'> is in effect:
+
+Unicode semantics are used for the case change.  Any subroutine named
+C<ToLower> will not be used.
+
+=item Otherwise:
+
+=over
+
+=item On EBCDIC platforms
+
+The results are what the C language system call C<tolower()> returns.
+
+=item On ASCII platforms
+
+ASCII semantics are used for the case change.  The lowercase of any character
+outside the ASCII range is the character itself.
+
+=back
+
+=back
+
 =item lcfirst EXPR
 X<lcfirst> X<lowercase>
 
@@ -2630,21 +2750,23 @@ X<lcfirst> X<lowercase>
 
 Returns the value of EXPR with the first character lowercased.  This
 is the internal function implementing the C<\l> escape in
-double-quoted strings.  Respects current LC_CTYPE locale if C<use
-locale> in force.  See L<perllocale> and L<perlunicode> for more
-details about locale and Unicode support.
+double-quoted strings.
 
 If EXPR is omitted, uses C<$_>.
 
+This function behaves the same way under various pragma, such as in a locale,
+as L</lc> does.
+
 =item length EXPR
 X<length> X<size>
 
 =item length
 
 Returns the length in I<characters> of the value of EXPR.  If EXPR is
-omitted, returns length of C<$_>.  Note that this cannot be used on
-an entire array or hash to find out how many elements these have.
-For that, use C<scalar @array> and C<scalar keys %hash> respectively.
+omitted, returns length of C<$_>.  If EXPR is undefined, returns C<undef>.
+Note that this cannot be used on an entire array or hash to find out how
+many elements these have. For that, use C<scalar @array> and C<scalar keys
+%hash> respectively.
 
 Note the I<characters>: if the EXPR is in Unicode, you will get the
 number of characters, not the number of bytes.  To get the length
@@ -2679,6 +2801,10 @@ block, file, or eval.  If more than one value is listed, the list must
 be placed in parentheses.  See L<perlsub/"Temporary Values via local()">
 for details, including issues with tied arrays and hashes.
 
+The C<delete local EXPR> construct can also be used to localize the deletion
+of array/hash elements to the current block.
+See L<perlsub/"Localized deletion of elements of composite types">.
+
 =item localtime EXPR
 X<localtime> X<ctime>
 
@@ -2724,7 +2850,8 @@ Wednesday.  C<$yday> is the day of the year, in the range C<0..364>
 C<$isdst> is true if the specified time occurs during Daylight Saving
 Time, false otherwise.
 
-If EXPR is omitted, C<localtime()> uses the current time (C<localtime(time)>).
+If EXPR is omitted, C<localtime()> uses the current time (as returned
+by time(3)).
 
 In scalar context, C<localtime()> returns the ctime(3) value:
 
@@ -2779,8 +2906,8 @@ The base-N log of a number is equal to the natural log of that number
 divided by the natural log of N.  For example:
 
     sub log10 {
-       my $n = shift;
-       return log($n)/log(10);
+        my $n = shift;
+        return log($n)/log(10);
     }
 
 See also L</exp> for the inverse operation.
@@ -2800,7 +2927,7 @@ If EXPR is omitted, stats C<$_>.
 
 =item m//
 
-The match operator.  See L<perlop>.
+The match operator.  See L<perlop/"Regexp Quote-Like Operators">.
 
 =item map BLOCK LIST
 X<map>
@@ -2824,7 +2951,7 @@ is just a funny way to write
 
     %hash = ();
     foreach (@array) {
-       $hash{get_a_key_for($_)} = $_;
+        $hash{get_a_key_for($_)} = $_;
     }
 
 Note that C<$_> is an alias to the list value, so it can be used to
@@ -2962,8 +3089,8 @@ The C<next> command is like the C<continue> statement in C; it starts
 the next iteration of the loop:
 
     LINE: while (<STDIN>) {
-       next LINE if /^#/;      # discard comments
-       #...
+        next LINE if /^#/;  # discard comments
+        #...
     }
 
 Note that if there were a C<continue> block on the above, it would get
@@ -3032,6 +3159,14 @@ X<open> X<pipe> X<file, open> X<fopen>
 Opens the file whose filename is given by EXPR, and associates it with
 FILEHANDLE.
 
+Simple examples to open a file for reading:
+
+    open(my $fh, '<', "input.txt") or die $!;
+
+and for writing:
+
+    open(my $fh, '>', "output.txt") or die $!;
+
 (The following is a comprehensive reference to open(): for a gentler
 introduction you may consider L<perlopentut>.)
 
@@ -3103,7 +3238,7 @@ You may use the three-argument form of open to specify IO "layers"
 that affect how the input and output are processed (see L<open> and
 L<PerlIO> for more details). For example
 
-  open(FH, "<:encoding(UTF-8)", "file")
+  open(my $fh, "<:encoding(UTF-8)", "file")
 
 will open the UTF-8 encoded file containing Unicode characters,
 see L<perluniintro>. Note that if layers are specified in the
@@ -3133,7 +3268,7 @@ working with an unopened filehandle is actually what you want to do.
 As a special case the 3-arg form with a read/write mode and the third
 argument being C<undef>:
 
-    open(TMP, "+>", undef) or die ...
+    open(my $tmp, "+>", undef) or die ...
 
 opens a filehandle to an anonymous temporary file.  Also using "+<"
 works for symmetry, but you really should consider writing something
@@ -3158,51 +3293,51 @@ Examples:
     open ARTICLE or die "Can't find article $ARTICLE: $!\n";
     while (<ARTICLE>) {...
 
-    open(LOG, '>>/usr/spool/news/twitlog');    # (log is reserved)
+    open(LOG, '>>/usr/spool/news/twitlog');  # (log is reserved)
     # if the open fails, output is discarded
 
-    open(DBASE, '+<', 'dbase.mine')            # open for update
-       or die "Can't open 'dbase.mine' for update: $!";
+    open(my $dbase, '+<', 'dbase.mine')      # open for update
+        or die "Can't open 'dbase.mine' for update: $!";
 
-    open(DBASE, '+<dbase.mine')                        # ditto
-       or die "Can't open 'dbase.mine' for update: $!";
+    open(my $dbase, '+<dbase.mine')          # ditto
+        or die "Can't open 'dbase.mine' for update: $!";
 
-    open(ARTICLE, '-|', "caesar <$article")     # decrypt article
-       or die "Can't start caesar: $!";
+    open(ARTICLE, '-|', "caesar <$article")  # decrypt article
+        or die "Can't start caesar: $!";
 
-    open(ARTICLE, "caesar <$article |")                # ditto
-       or die "Can't start caesar: $!";
+    open(ARTICLE, "caesar <$article |")      # ditto
+        or die "Can't start caesar: $!";
 
-    open(EXTRACT, "|sort >Tmp$$")              # $$ is our process id
-       or die "Can't start sort: $!";
+    open(EXTRACT, "|sort >Tmp$$")            # $$ is our process id
+        or die "Can't start sort: $!";
 
     # in memory files
     open(MEMORY,'>', \$var)
-       or die "Can't open memory file: $!";
-    print MEMORY "foo!\n";                     # output will end up in $var
+        or die "Can't open memory file: $!";
+    print MEMORY "foo!\n";                   # output will end up in $var
 
     # process argument list of files along with any includes
 
     foreach $file (@ARGV) {
-       process($file, 'fh00');
+        process($file, 'fh00');
     }
 
     sub process {
-       my($filename, $input) = @_;
-       $input++;               # this is a string increment
-       unless (open($input, $filename)) {
-           print STDERR "Can't open $filename: $!\n";
-           return;
-       }
-
-       local $_;
-       while (<$input>) {              # note use of indirection
-           if (/^#include "(.*)"/) {
-               process($1, $input);
-               next;
-           }
-           #...                # whatever
-       }
+        my($filename, $input) = @_;
+        $input++;    # this is a string increment
+        unless (open($input, $filename)) {
+            print STDERR "Can't open $filename: $!\n";
+            return;
+        }
+
+        local $_;
+        while (<$input>) {    # note use of indirection
+            if (/^#include "(.*)"/) {
+                process($1, $input);
+                next;
+            }
+            #...          # whatever
+        }
     }
 
 See L<perliol> for detailed info on PerlIO.
@@ -3210,7 +3345,7 @@ See L<perliol> for detailed info on PerlIO.
 You may also, in the Bourne shell tradition, specify an EXPR beginning
 with C<< '>&' >>, in which case the rest of the string is interpreted
 as the name of a filehandle (or file descriptor, if numeric) to be
-duped (as L<dup(2)>) and opened.  You may use C<&> after C<< > >>,
+duped (as C<dup(2)>) and opened.  You may use C<&> after C<< > >>,
 C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>.
 The mode you specify should match the mode of the original filehandle.
 (Duping a filehandle does not take into account any existing contents
@@ -3227,11 +3362,11 @@ C<STDERR> using various methods:
     open STDOUT, '>', "foo.out" or die "Can't redirect STDOUT: $!";
     open STDERR, ">&STDOUT"     or die "Can't dup STDOUT: $!";
 
-    select STDERR; $| = 1;     # make unbuffered
-    select STDOUT; $| = 1;     # make unbuffered
+    select STDERR; $| = 1;  # make unbuffered
+    select STDOUT; $| = 1;  # make unbuffered
 
-    print STDOUT "stdout 1\n"; # this works for
-    print STDERR "stderr 1\n";         # subprocesses too
+    print STDOUT "stdout 1\n";  # this works for
+    print STDERR "stderr 1\n";  # subprocesses too
 
     open STDOUT, ">&", $oldout or die "Can't dup \$oldout: $!";
     open STDERR, ">&OLDERR"    or die "Can't dup OLDERR: $!";
@@ -3241,7 +3376,7 @@ C<STDERR> using various methods:
 
 If you specify C<< '<&=X' >>, where C<X> is a file descriptor number
 or a filehandle, then Perl will do an equivalent of C's C<fdopen> of
-that file descriptor (and not call L<dup(2)>); this is more
+that file descriptor (and not call C<dup(2)>); this is more
 parsimonious of file descriptors.  For example:
 
     # open for input, reusing the fileno of $fd
@@ -3354,7 +3489,7 @@ but will not work on a filename which happens to have a trailing space, while
 
 will have exactly the opposite restrictions.
 
-If you want a "real" C C<open> (see L<open(2)> on your system), then you
+If you want a "real" C C<open> (see C<open(2)> on your system), then you
 should use the C<sysopen> function, which involves no such magic (but
 may use subtly different filemodes than Perl open(), which is mapped
 to C fopen()).  This is
@@ -3362,7 +3497,7 @@ another way to protect your filenames from interpretation.  For example:
 
     use IO::Handle;
     sysopen(HANDLE, $path, O_RDWR|O_CREAT|O_EXCL)
-       or die "sysopen $path: $!";
+        or die "sysopen $path: $!";
     $oldfh = select(HANDLE); $| = 1; select($oldfh);
     print HANDLE "stuff $$\n";
     seek(HANDLE, 0, 0);
@@ -3376,14 +3511,14 @@ them, and automatically close whenever and however you leave that scope:
     use IO::File;
     #...
     sub read_myfile_munged {
-       my $ALL = shift;
-       my $handle = new IO::File;
-       open($handle, "myfile") or die "myfile: $!";
-       $first = <$handle>
-           or return ();     # Automatically closed here.
-       mung $first or die "mung failed";       # Or here.
-       return $first, <$handle> if $ALL;       # Or here.
-       $first;                                 # Or here.
+        my $ALL = shift;
+        my $handle = IO::File->new;
+        open($handle, "myfile") or die "myfile: $!";
+        $first = <$handle>
+            or return ();     # Automatically closed here.
+        mung $first or die "mung failed";  # Or here.
+        return $first, <$handle> if $ALL;  # Or here.
+        $first;          # Or here.
     }
 
 See L</seek> for some details about mixing reading and writing.
@@ -3399,6 +3534,8 @@ scalar variable (or array or hash element), the variable is assigned a
 reference to a new anonymous dirhandle.
 DIRHANDLEs have their own namespace separate from FILEHANDLEs.
 
+See example at C<readdir>.
+
 =item ord EXPR
 X<ord> X<encoding>
 
@@ -3446,11 +3583,11 @@ of the declaration, not at the point of use.  This means the following
 behavior holds:
 
     package Foo;
-    our $bar;          # declares $Foo::bar for rest of lexical scope
+    our $bar;      # declares $Foo::bar for rest of lexical scope
     $bar = 20;
 
     package Bar;
-    print $bar;                # prints 20, as it refers to $Foo::bar
+    print $bar;    # prints 20, as it refers to $Foo::bar
 
 Multiple C<our> declarations with the same name in the same lexical
 scope are allowed if they are in different packages.  If they happen
@@ -3462,15 +3599,15 @@ merely redundant.
 
     use warnings;
     package Foo;
-    our $bar;          # declares $Foo::bar for rest of lexical scope
+    our $bar;      # declares $Foo::bar for rest of lexical scope
     $bar = 20;
 
     package Bar;
-    our $bar = 30;     # declares $Bar::bar for rest of lexical scope
-    print $bar;                # prints 30
+    our $bar = 30; # declares $Bar::bar for rest of lexical scope
+    print $bar;    # prints 30
 
-    our $bar;          # emits warning but has no other effect
-    print $bar;                # still prints 30
+    our $bar;      # emits warning but has no other effect
+    print $bar;    # still prints 30
 
 An C<our> declaration may also have a list of attributes associated
 with it.
@@ -3492,74 +3629,76 @@ like its machine-level representation.  For example, on 32-bit machines
 an integer may be represented by a sequence of 4 bytes that will be 
 converted to a sequence of 4 characters.
 
+See L<perlpacktut> for an introduction to this function.
+
 The TEMPLATE is a sequence of characters that give the order and type
 of values, as follows:
 
-    a  A string with arbitrary binary data, will be null padded.
-    A  A text (ASCII) string, will be space padded.
-    Z  A null terminated (ASCIZ) string, will be null padded.
+    a  A string with arbitrary binary data, will be null padded.
+    A  A text (ASCII) string, will be space padded.
+    Z  A null terminated (ASCIZ) string, will be null padded.
 
-    b  A bit string (ascending bit order inside each byte, like vec()).
-    B  A bit string (descending bit order inside each byte).
-    h  A hex string (low nybble first).
-    H  A hex string (high nybble first).
+    b  A bit string (ascending bit order inside each byte, like vec()).
+    B  A bit string (descending bit order inside each byte).
+    h  A hex string (low nybble first).
+    H  A hex string (high nybble first).
 
-    c  A signed char (8-bit) value.
-    C  An unsigned char (octet) value.
+    c  A signed char (8-bit) value.
+    C  An unsigned char (octet) value.
     W   An unsigned char value (can be greater than 255).
 
-    s  A signed short (16-bit) value.
-    S  An unsigned short value.
+    s  A signed short (16-bit) value.
+    S  An unsigned short value.
 
-    l  A signed long (32-bit) value.
-    L  An unsigned long value.
+    l  A signed long (32-bit) value.
+    L  An unsigned long value.
 
-    q  A signed quad (64-bit) value.
-    Q  An unsigned quad value.
-         (Quads are available only if your system supports 64-bit
-          integer values _and_ if Perl has been compiled to support those.
+    q  A signed quad (64-bit) value.
+    Q  An unsigned quad value.
+      (Quads are available only if your system supports 64-bit
+       integer values _and_ if Perl has been compiled to support those.
            Causes a fatal error otherwise.)
 
-    i  A signed integer value.
-    I  A unsigned integer value.
-         (This 'integer' is _at_least_ 32 bits wide.  Its exact
+    i  A signed integer value.
+    I  A unsigned integer value.
+      (This 'integer' is _at_least_ 32 bits wide.  Its exact
            size depends on what a local C compiler calls 'int'.)
 
-    n  An unsigned short (16-bit) in "network" (big-endian) order.
-    N  An unsigned long (32-bit) in "network" (big-endian) order.
-    v  An unsigned short (16-bit) in "VAX" (little-endian) order.
-    V  An unsigned long (32-bit) in "VAX" (little-endian) order.
+    n  An unsigned short (16-bit) in "network" (big-endian) order.
+    N  An unsigned long (32-bit) in "network" (big-endian) order.
+    v  An unsigned short (16-bit) in "VAX" (little-endian) order.
+    V  An unsigned long (32-bit) in "VAX" (little-endian) order.
 
     j   A Perl internal signed integer value (IV).
     J   A Perl internal unsigned integer value (UV).
 
-    f  A single-precision float in the native format.
-    d  A double-precision float in the native format.
+    f  A single-precision float in the native format.
+    d  A double-precision float in the native format.
 
-    F  A Perl internal floating point value (NV) in the native format
-    D  A long double-precision float in the native format.
-         (Long doubles are available only if your system supports long
-          double values _and_ if Perl has been compiled to support those.
+    F  A Perl internal floating point value (NV) in the native format
+    D  A long double-precision float in the native format.
+      (Long doubles are available only if your system supports long
+       double values _and_ if Perl has been compiled to support those.
            Causes a fatal error otherwise.)
 
-    p  A pointer to a null-terminated string.
-    P  A pointer to a structure (fixed-length string).
+    p  A pointer to a null-terminated string.
+    P  A pointer to a structure (fixed-length string).
 
-    u  A uuencoded string.
-    U  A Unicode character number.  Encodes to a character in character mode
+    u  A uuencoded string.
+    U  A Unicode character number.  Encodes to a character in character mode
         and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in byte mode.
 
-    w  A BER compressed integer (not an ASN.1 BER, see perlpacktut for
-       details).  Its bytes represent an unsigned integer in base 128,
-       most significant digit first, with as few digits as possible.  Bit
-       eight (the high bit) is set on each byte except the last.
+    w  A BER compressed integer (not an ASN.1 BER, see perlpacktut for
+    details).  Its bytes represent an unsigned integer in base 128,
+    most significant digit first, with as few digits as possible.  Bit
+    eight (the high bit) is set on each byte except the last.
 
-    x  A null byte.
-    X  Back up a byte.
-    @  Null fill or truncate to absolute position, counted from the
+    x  A null byte.
+    X  Back up a byte.
+    @  Null fill or truncate to absolute position, counted from the
         start of the innermost ()-group.
     .   Null fill or truncate to absolute position specified by value.
-    (  Start of a ()-group.
+    (  Start of a ()-group.
 
 One or more of the modifiers below may optionally follow some letters in the
 TEMPLATE (the second column lists the letters for which the modifier is
@@ -3756,8 +3895,8 @@ exactly 32 bits, the native C<long> (as seen by the local C compiler)
 may be larger.  This is an issue mainly in 64-bit platforms.  You can
 see whether using C<!> makes any difference by
 
-       print length(pack("s")), " ", length(pack("s!")), "\n";
-       print length(pack("l")), " ", length(pack("l!")), "\n";
+    print length(pack("s")), " ", length(pack("s!")), "\n";
+    print length(pack("l")), " ", length(pack("l!")), "\n";
 
 C<i!> and C<I!> also work but only because of completeness;
 they are identical to C<i> and C<I>.
@@ -3783,8 +3922,8 @@ because they obey the native byteorder and endianness.  For example a
 4-byte integer 0x12345678 (305419896 decimal) would be ordered natively
 (arranged in and handled by the CPU registers) into bytes as
 
-       0x12 0x34 0x56 0x78     # big-endian
-       0x78 0x56 0x34 0x12     # little-endian
+    0x12 0x34 0x56 0x78  # big-endian
+    0x78 0x56 0x34 0x12  # little-endian
 
 Basically, the Intel and VAX CPUs are little-endian, while everybody
 else, for example Motorola m68k/88k, PPC, Sparc, HP PA, Power, and
@@ -3799,19 +3938,19 @@ the egg-eating habits of the Lilliputians.
 
 Some systems may have even weirder byte orders such as
 
-       0x56 0x78 0x12 0x34
-       0x34 0x12 0x78 0x56
+   0x56 0x78 0x12 0x34
+   0x34 0x12 0x78 0x56
 
 You can see your system's preference with
 
-       print join(" ", map { sprintf "%#02x", $_ }
+   print join(" ", map { sprintf "%#02x", $_ }
                             unpack("W*",pack("L",0x12345678))), "\n";
 
 The byteorder on the platform where Perl was built is also available
 via L<Config>:
 
-       use Config;
-       print $Config{byteorder}, "\n";
+    use Config;
+    print $Config{byteorder}, "\n";
 
 Byteorders C<'1234'> and C<'12345678'> are little-endian, C<'4321'>
 and C<'87654321'> are big-endian.
@@ -3982,7 +4121,7 @@ Examples:
     # "@utmp1" eq "@utmp2"
 
     sub bintodec {
-       unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
+        unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
     }
 
     $foo = pack('sx2l', 12, 34);
@@ -4004,10 +4143,10 @@ Examples:
 
 The same template may generally also be used in unpack().
 
-=item package NAMESPACE
-X<package> X<module> X<namespace>
+=item package NAMESPACE VERSION
+X<package> X<module> X<namespace> X<version>
 
-=item package
+=item package NAMESPACE
 
 Declares the compilation unit as being in the given namespace.  The scope
 of the package declaration is from the declaration itself through the end
@@ -4025,11 +4164,10 @@ If the package name is null, the C<main> package as assumed.  That is,
 C<$::sail> is equivalent to C<$main::sail> (as well as to C<$main'sail>,
 still seen in older code).
 
-If NAMESPACE is omitted, then there is no current package, and all
-identifiers must be fully qualified or lexicals.  However, you are
-strongly advised not to make use of this feature. Its use can cause
-unexpected behaviour, even crashing some versions of Perl. It is
-deprecated, and will be removed from a future release.
+If VERSION is provided, C<package> also sets the C<$VERSION> variable in the
+given namespace.  VERSION must be be a numeric literal or v-string; it is
+parsed exactly the same way as a VERSION argument to C<use MODULE VERSION>.
+C<$VERSION> should only be set once per package.
 
 See L<perlmod/"Packages"> for more information about packages, modules,
 and classes.  See L<perlsub> for other scoping issues.
@@ -4056,9 +4194,7 @@ X<pop> X<stack>
 =item pop
 
 Pops and returns the last value of the array, shortening the array by
-one element.  Has an effect similar to
-
-    $ARRAY[$#ARRAY--]
+one element.
 
 If there are no elements in the array, returns the undefined value
 (although this may happen at other times as well).  If ARRAY is
@@ -4116,6 +4252,9 @@ you will have to use a block returning the filehandle value instead:
     print { $files[$i] } "stuff\n";
     print { $OK ? STDOUT : STDERR } "stuff\n";
 
+Printing to a closed pipe or socket will generate a SIGPIPE signal.  See
+L<perlipc> for more on signal handling.
+
 =item printf FILEHANDLE FORMAT, LIST
 X<printf>
 
@@ -4142,10 +4281,10 @@ the function whose prototype you want to retrieve.
 
 If FUNCTION is a string starting with C<CORE::>, the rest is taken as a
 name for Perl builtin.  If the builtin is not I<overridable> (such as
-C<qw//>) or its arguments cannot be expressed by a prototype (such as
-C<system>) returns C<undef> because the builtin does not really behave
-like a Perl function.  Otherwise, the string describing the equivalent
-prototype is returned.
+C<qw//>) or if its arguments cannot be adequately expressed by a prototype
+(such as C<system>), prototype() returns C<undef>, because the builtin
+does not really behave like a Perl function.  Otherwise, the string
+describing the equivalent prototype is returned.
 
 =item push ARRAY,LIST
 X<push> X<stack>
@@ -4155,7 +4294,7 @@ onto the end of ARRAY.  The length of ARRAY increases by the length of
 LIST.  Has the same effect as
 
     for $value (LIST) {
-       $ARRAY[++$#ARRAY] = $value;
+        $ARRAY[++$#ARRAY] = $value;
     }
 
 but is more efficient.  Returns the number of elements in the array following
@@ -4165,13 +4304,15 @@ the completed C<push>.
 
 =item qq/STRING/
 
-=item qr/STRING/
-
 =item qx/STRING/
 
 =item qw/STRING/
 
-Generalized quotes.  See L<perlop/"Regexp Quote-Like Operators">.
+Generalized quotes.  See L<perlop/"Quote-Like Operators">.
+
+=item qr/STRING/
+
+Regexp-like quote.  See L<perlop/"Regexp Quote-Like Operators">.
 
 =item quotemeta EXPR
 X<quotemeta> X<metacharacter>
@@ -4187,6 +4328,32 @@ the C<\Q> escape in double-quoted strings.
 
 If EXPR is omitted, uses C<$_>.
 
+quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into
+regular expressions, because by default an interpolated variable will be
+considered a mini-regular expression. For example:
+
+    my $sentence = 'The quick brown fox jumped over the lazy dog';
+    my $substring = 'quick.*?fox';
+    $sentence =~ s{$substring}{big bad wolf};
+
+Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>.
+
+On the other hand:
+
+    my $sentence = 'The quick brown fox jumped over the lazy dog';
+    my $substring = 'quick.*?fox';
+    $sentence =~ s{\Q$substring\E}{big bad wolf};
+
+Or:
+
+    my $sentence = 'The quick brown fox jumped over the lazy dog';
+    my $substring = 'quick.*?fox';
+    my $quoted_substring = quotemeta($substring);
+    $sentence =~ s{$quoted_substring}{big bad wolf};
+
+Will both leave the sentence as is. Normally, when accepting string input from
+the user, quotemeta() or C<\Q> must be used.
+
 =item rand EXPR
 X<rand> X<random>
 
@@ -4252,9 +4419,18 @@ If you're planning to filetest the return values out of a C<readdir>, you'd
 better prepend the directory in question.  Otherwise, because we didn't
 C<chdir> there, it would have been testing the wrong file.
 
-    opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
-    @dots = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR);
-    closedir DIR;
+    opendir(my $dh, $some_dir) || die "can't opendir $some_dir: $!";
+    @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
+    closedir $dh;
+
+As of Perl 5.11.2 you can use a bare C<readdir> in a C<while> loop,
+which will set C<$_> on every iteration.
+
+    opendir(my $dh, $some_dir) || die;
+    while(readdir $dh) {
+        print "$some_dir/$_\n";
+    }
+    closedir $dh;
 
 =item readline EXPR
 
@@ -4264,12 +4440,12 @@ X<readline> X<gets> X<fgets>
 Reads from the filehandle whose typeglob is contained in EXPR (or from
 *ARGV if EXPR is not provided).  In scalar context, each call reads and
 returns the next line, until end-of-file is reached, whereupon the
-subsequent call returns undef.  In list context, reads until end-of-file
+subsequent call returns C<undef>.  In list context, reads until end-of-file
 is reached and returns a list of lines.  Note that the notion of "line"
 used here is however you may have defined it with C<$/> or
 C<$INPUT_RECORD_SEPARATOR>).  See L<perlvar/"$/">.
 
-When C<$/> is set to C<undef>, when readline() is in scalar
+When C<$/> is set to C<undef>, when C<readline> is in scalar
 context (i.e. file slurp mode), and when an empty file is read, it
 returns C<''> the first time, followed by C<undef> subsequently.
 
@@ -4278,21 +4454,31 @@ operator, but you can use it directly.  The C<< <EXPR> >>
 operator is discussed in more detail in L<perlop/"I/O Operators">.
 
     $line = <STDIN>;
-    $line = readline(*STDIN);          # same thing
+    $line = readline(*STDIN);    # same thing
 
-If readline encounters an operating system error, C<$!> will be set with the
-corresponding error message.  It can be helpful to check C<$!> 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 C<readline>, and takes the necessary
-steps to ensure that C<readline> was successful.
+If C<readline> encounters an operating system error, C<$!> will be set
+with the corresponding error message.  It can be helpful to check
+C<$!> 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
+C<readline> and dies if the result is not defined.
 
-    for (;;) {
-        undef $!;
-        unless (defined( $line = <> )) {
-            die $! if $!;
-            last; # reached EOF
+    while ( ! eof($fh) ) {
+        defined( $_ = <$fh> ) or die "readline failed: $!";
+        ...
+    }
+
+Note that you have can't handle C<readline> errors that way with the
+C<ARGV> filehandle. In that case, you have to open each element of
+C<@ARGV> yourself since C<eof> handles C<ARGV> differently.
+
+    foreach my $arg (@ARGV) {
+        open(my $fh, $arg) or warn "Can't open $arg: $!";
+
+        while ( ! eof($fh) ) {
+            defined( $_ = <$fh> )
+                or die "readline failed for $arg: $!";
+            ...
         }
-        # ...
     }
 
 =item readlink EXPR
@@ -4335,10 +4521,10 @@ See L<perlipc/"UDP: Message Passing"> for examples.
 Note the I<characters>: depending on the status of the socket, either
 (8-bit) bytes or characters are received.  By default all sockets
 operate on bytes, but for example if the socket has been changed using
-binmode() to operate with the C<:utf8> I/O layer (see the C<open>
-pragma, L<open>), the I/O will operate on UTF-8 encoded Unicode
-characters, not bytes.  Similarly for the C<:encoding> pragma:
-in that case pretty much any characters can be read.
+binmode() to operate with the C<:encoding(utf8)> I/O layer (see the
+C<open> pragma, L<open>), the I/O will operate on UTF-8 encoded Unicode
+characters, not bytes.  Similarly for the C<:encoding> pragma: in that
+case pretty much any characters can be read.
 
 =item redo LABEL
 X<redo>
@@ -4354,18 +4540,18 @@ normally use this command:
     # a simpleminded Pascal comment stripper
     # (warning: assumes no { or } in strings)
     LINE: while (<STDIN>) {
-       while (s|({.*}.*){.*}|$1 |) {}
-       s|{.*}| |;
-       if (s|{.*| |) {
-           $front = $_;
-           while (<STDIN>) {
-               if (/}/) {      # end of comment?
-                   s|^|$front\{|;
-                   redo LINE;
-               }
-           }
-       }
-       print;
+        while (s|({.*}.*){.*}|$1 |) {}
+        s|{.*}| |;
+        if (s|{.*| |) {
+            $front = $_;
+            while (<STDIN>) {
+                if (/}/) {  # end of comment?
+                    s|^|$front\{|;
+                    redo LINE;
+                }
+            }
+        }
+        print;
     }
 
 C<redo> cannot be used to retry a block which returns a value such as
@@ -4406,10 +4592,10 @@ If the referenced object has been blessed into a package, then that package
 name is returned instead.  You can think of C<ref> as a C<typeof> operator.
 
     if (ref($r) eq "HASH") {
-       print "r is a reference to a hash.\n";
+        print "r is a reference to a hash.\n";
     }
     unless (ref($r)) {
-       print "r is not a reference at all.\n";
+        print "r is not a reference at all.\n";
     }
 
 The return value C<LVALUE> indicates a reference to an lvalue that is not
@@ -4459,9 +4645,9 @@ avoided, because it leads to misleading error messages under earlier
 versions of Perl that do not support this syntax.  The equivalent numeric
 version should be used instead.
 
-    require v5.6.1;    # run time version check
-    require 5.6.1;     # ditto
-    require 5.006_001; # ditto; preferred for backwards compatibility
+    require v5.6.1;     # run time version check
+    require 5.6.1;      # ditto
+    require 5.006_001;  # ditto; preferred for backwards compatibility
 
 Otherwise, C<require> demands that a library file be included if it
 hasn't already been included.  The file is included via the do-FILE
@@ -4514,7 +4700,7 @@ modules does not risk altering your namespace.
 
 In other words, if you try this:
 
-        require Foo::Bar;    # a splendid bareword
+        require Foo::Bar;     # a splendid bareword
 
 The require function will actually look for the "F<Foo/Bar.pm>" file in the
 directories specified in the C<@INC> array.
@@ -4522,9 +4708,9 @@ directories specified in the C<@INC> array.
 But if you try this:
 
         $class = 'Foo::Bar';
-        require $class;             # $class is not a bareword
+        require $class;       # $class is not a bareword
     #or
-        require "Foo::Bar";  # not a bareword because of the ""
+        require "Foo::Bar";   # not a bareword because of the ""
 
 The require function will look for the "F<Foo::Bar>" file in the @INC array and
 will complain about not finding "F<Foo::Bar>" there.  In this case you can do:
@@ -4561,7 +4747,7 @@ A reference to a subroutine. If there is no filehandle (previous item),
 then this subroutine is expected to generate one line of source code per
 call, writing the line into C<$_> and returning 1, then returning 0 at
 "end of file". If there is a filehandle, then the subroutine will be
-called to act a simple source filter, with the line as read in C<$_>.
+called to act as a simple source filter, with the line as read in C<$_>.
 Again, return 1 for each valid line, and 0 after all lines have been
 returned.
 
@@ -4587,18 +4773,18 @@ In other words, you can write:
 
     push @INC, \&my_sub;
     sub my_sub {
-       my ($coderef, $filename) = @_;  # $coderef is \&my_sub
-       ...
+        my ($coderef, $filename) = @_;  # $coderef is \&my_sub
+        ...
     }
 
 or:
 
     push @INC, [ \&my_sub, $x, $y, ... ];
     sub my_sub {
-       my ($arrayref, $filename) = @_;
-       # Retrieve $x, $y, ...
-       my @parameters = @$arrayref[1..$#$arrayref];
-       ...
+        my ($arrayref, $filename) = @_;
+        # Retrieve $x, $y, ...
+        my @parameters = @$arrayref[1..$#$arrayref];
+        ...
     }
 
 If the hook is an object, it must provide an INC method that will be
@@ -4610,12 +4796,12 @@ into package C<main>.)  Here is a typical code layout:
     package Foo;
     sub new { ... }
     sub Foo::INC {
-       my ($self, $filename) = @_;
-       ...
+        my ($self, $filename) = @_;
+        ...
     }
 
     # In the main program
-    push @INC, new Foo(...);
+    push @INC, Foo->new(...);
 
 Note that these hooks are also permitted to set the %INC entry
 corresponding to the files they have loaded. See L<perlvar/%INC>.
@@ -4634,11 +4820,11 @@ allowed for ranges).  All variables and arrays beginning with one of
 those letters are reset to their pristine state.  If the expression is
 omitted, one-match searches (C<?pattern?>) are reset to match again.  Resets
 only variables or searches in the current package.  Always returns
-1.  Examples:
+1. Examples:
 
-    reset 'X';         # reset all X variables
-    reset 'a-z';       # reset lower case variables
-    reset;             # just reset ?one-time? searches
+    reset 'X';      # reset all X variables
+    reset 'a-z';    # reset lower case variables
+    reset;          # just reset ?one-time? searches
 
 Resetting C<"A-Z"> is not recommended because you'll wipe out your
 C<@ARGV> and C<@INC> arrays and your C<%ENV> hash.  Resets only package
@@ -4670,20 +4856,27 @@ of LIST in the opposite order.  In scalar context, concatenates the
 elements of LIST and returns a string value with all characters
 in the opposite order.
 
-    print reverse <>;          # line tac, last line first
+    print join(", ", reverse "world", "Hello"); # Hello, world
 
-    undef $/;                  # for efficiency of <>
-    print scalar reverse <>;   # character tac, last line tsrif
+    print scalar reverse "dlrow ,", "olleH";    # Hello, world
 
 Used without arguments in scalar context, reverse() reverses C<$_>.
 
+    $_ = "dlrow ,olleH";
+    print reverse;                              # No output, list context
+    print scalar reverse;                       # Hello, world
+
+Note that reversing an array to itself (as in C<@a = reverse @a>) will
+preserve non-existent elements whenever possible, i.e. for non magical
+arrays or tied arrays with C<EXISTS> and C<DELETE> methods.
+
 This operator is also handy for inverting a hash, although there are some
 caveats.  If a value is duplicated in the original hash, only one of those
 can be represented as a key in the inverted hash.  Also, this has to
 unwind one hash and build a whole new one, which may take some time
 on a large hash, such as from a DBM file.
 
-    %by_name = reverse %by_address;    # Invert the hash
+    %by_name = reverse %by_address;  # Invert the hash
 
 =item rewinddir DIRHANDLE
 X<rewinddir>
@@ -4714,7 +4907,7 @@ the C<rmtree> function of the L<File::Path> module.
 
 =item s///
 
-The substitution operator.  See L<perlop>.
+The substitution operator.  See L<perlop/"Regexp Quote-Like Operators">.
 
 =item say FILEHANDLE LIST
 X<say>
@@ -4751,12 +4944,12 @@ evaluated in scalar context.  This is seldom what you want.
 
 The following single statement:
 
-       print uc(scalar(&foo,$bar)),$baz;
+    print uc(scalar(&foo,$bar)),$baz;
 
 is the moral equivalent of these two:
 
-       &foo;
-       print(uc($bar),$baz);
+    &foo;
+    print(uc($bar),$baz);
 
 See L<perlop> for more details on unary operators and the comma operator.
 
@@ -4774,7 +4967,7 @@ of the file) from the Fcntl module.  Returns C<1> upon success, C<0>
 otherwise.
 
 Note the I<in bytes>: even if the filehandle has been set to
-operate on characters (for example by using the C<:utf8> open
+operate on characters (for example by using the C<:encoding(utf8)> open
 layer), tell() will return byte offsets, not character offsets
 (because implementing that would render seek() and tell() rather slow).
 
@@ -4799,12 +4992,12 @@ If that doesn't work (some IO implementations are particularly
 cantankerous), then you may need something more like this:
 
     for (;;) {
-       for ($curpos = tell(FILE); $_ = <FILE>;
+        for ($curpos = tell(FILE); $_ = <FILE>;
              $curpos = tell(FILE)) {
-           # search for some stuff and put it into files
-       }
-       sleep($for_a_while);
-       seek(FILE, $curpos, 0);
+            # search for some stuff and put it into files
+        }
+        sleep($for_a_while);
+        seek(FILE, $curpos, 0);
     }
 
 =item seekdir DIRHANDLE,POS
@@ -4859,12 +5052,12 @@ If you want to select on many filehandles you might wish to write a
 subroutine:
 
     sub fhbits {
-       my(@fhlist) = split(' ',$_[0]);
-       my($bits);
-       for (@fhlist) {
-           vec($bits,fileno($_),1) = 1;
-       }
-       $bits;
+        my(@fhlist) = split(' ',$_[0]);
+        my($bits);
+        for (@fhlist) {
+            vec($bits,fileno($_),1) = 1;
+        }
+        $bits;
     }
     $rin = fhbits('STDIN TTY SOCK');
 
@@ -4964,10 +5157,10 @@ L<perlipc/"UDP: Message Passing"> for examples.
 Note the I<characters>: depending on the status of the socket, either
 (8-bit) bytes or characters are sent.  By default all sockets operate
 on bytes, but for example if the socket has been changed using
-binmode() to operate with the C<:utf8> I/O layer (see L</open>, or the
-C<open> pragma, L<open>), the I/O will operate on UTF-8 encoded
-Unicode characters, not bytes.  Similarly for the C<:encoding> pragma:
-in that case pretty much any characters can be sent.
+binmode() to operate with the C<:encoding(utf8)> I/O layer (see
+L</open>, or the C<open> pragma, L<open>), the I/O will operate on UTF-8
+encoded Unicode characters, not bytes.  Similarly for the C<:encoding>
+pragma: in that case pretty much any characters can be sent.
 
 =item setpgrp PID,PGRP
 X<setpgrp> X<group>
@@ -5068,6 +5261,10 @@ It's also a more insistent form of close because it also
 disables the file descriptor in any forked copies in other
 processes.
 
+Returns C<1> for success. In the case of error, returns C<undef> if
+the first argument is not a valid filehandle, or returns C<0> and sets
+C<$!> for any other failure.
+
 =item sin EXPR
 X<sin> X<sine> X<asin> X<arcsine>
 
@@ -5087,10 +5284,18 @@ X<sleep> X<pause>
 =item sleep
 
 Causes the script to sleep for EXPR seconds, or forever if no EXPR.
+Returns the number of seconds actually slept.  
+
 May be interrupted if the process receives a signal such as C<SIGALRM>.
-Returns the number of seconds actually slept.  You probably cannot
-mix C<alarm> and C<sleep> calls, because C<sleep> is often implemented
-using C<alarm>.
+
+    eval {
+        local $SIG{ALARM} = sub { die "Alarm!\n" };
+        sleep;
+    };
+    die $@ unless $@ eq "Alarm!\n";
+
+You probably cannot mix C<alarm> and C<sleep> calls, because C<sleep>
+is often implemented using C<alarm>.
 
 On some older systems, it may sleep up to a full second less than what
 you requested, depending on how it counts seconds.  Most modern systems
@@ -5098,11 +5303,12 @@ always sleep the full amount.  They may appear to sleep longer than that,
 however, because your process might not be scheduled right away in a
 busy multitasking system.
 
-For delays of finer granularity than one second, you may use Perl's
-C<syscall> interface to access setitimer(2) if your system supports
-it, or else see L</select> above.  The Time::HiRes module (from CPAN,
-and starting from Perl 5.8 part of the standard distribution) may also
-help.
+For delays of finer granularity than one second, the Time::HiRes module
+(from CPAN, and starting from Perl 5.8 part of the standard
+distribution) provides usleep().  You may also use Perl's four-argument
+version of select() leaving the first three arguments undefined, or you
+might be able to use the C<syscall> interface to access setitimer(2) if
+your system supports it. See L<perlfaq8> for details.
 
 See also the POSIX module's C<pause> function.
 
@@ -5198,100 +5404,117 @@ the original quicksort was faster.  5.8 has a sort pragma for
 limited control of the sort.  Its rather blunt control of the
 underlying algorithm may not persist into future Perls, but the
 ability to characterize the input or output in implementation
-independent ways quite probably will.  See L<sort>.
+independent ways quite probably will.  See L<the sort pragma|sort>.
 
 Examples:
 
     # sort lexically
     @articles = sort @files;
-
+    
     # same thing, but with explicit sort routine
     @articles = sort {$a cmp $b} @files;
-
+    
     # now case-insensitively
     @articles = sort {uc($a) cmp uc($b)} @files;
-
+    
     # same thing in reversed order
     @articles = sort {$b cmp $a} @files;
-
+    
     # sort numerically ascending
     @articles = sort {$a <=> $b} @files;
-
+    
     # sort numerically descending
     @articles = sort {$b <=> $a} @files;
-
+    
     # this sorts the %age hash by value instead of key
     # using an in-line function
     @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
-
+    
     # sort using explicit subroutine name
     sub byage {
-       $age{$a} <=> $age{$b};  # presuming numeric
+    $age{$a} <=> $age{$b};  # presuming numeric
     }
     @sortedclass = sort byage @class;
-
+    
     sub backwards { $b cmp $a }
     @harry  = qw(dog cat x Cain Abel);
     @george = qw(gone chased yz Punished Axed);
     print sort @harry;
-           # prints AbelCaincatdogx
+        # prints AbelCaincatdogx
     print sort backwards @harry;
-           # prints xdogcatCainAbel
+        # prints xdogcatCainAbel
     print sort @george, 'to', @harry;
-           # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
+        # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
 
     # inefficiently sort by descending numeric compare using
     # the first integer after the first = sign, or the
     # whole record case-insensitively otherwise
 
-    @new = sort {
-       ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
-                           ||
-                   uc($a)  cmp  uc($b)
+    my @new = sort {
+        ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
+            ||
+        uc($a)  cmp  uc($b)
     } @old;
 
     # same thing, but much more efficiently;
     # we'll build auxiliary indices instead
     # for speed
-    @nums = @caps = ();
+    my @nums = @caps = ();
     for (@old) {
-       push @nums, /=(\d+)/;
-       push @caps, uc($_);
+        push @nums, ( /=(\d+)/ ? $1 : undef );
+        push @caps, uc($_);
     }
 
-    @new = @old[ sort {
-                       $nums[$b] <=> $nums[$a]
-                                ||
-                       $caps[$a] cmp $caps[$b]
-                      } 0..$#old
-              ];
+    my @new = @old[ sort {
+        $nums[$b] <=> $nums[$a]
+            ||
+        $caps[$a] cmp $caps[$b]
+        } 0..$#old
+    ];
 
     # same thing, but without any temps
     @new = map { $_->[0] }
            sort { $b->[1] <=> $a->[1]
-                           ||
-                  $a->[2] cmp $b->[2]
-           } map { [$_, /=(\d+)/, uc($_)] } @old;
+               ||
+           $a->[2] cmp $b->[2]
+    } map { [$_, /=(\d+)/, uc($_)] } @old;
 
     # using a prototype allows you to use any comparison subroutine
     # as a sort subroutine (including other package's subroutines)
     package other;
-    sub backwards ($$) { $_[1] cmp $_[0]; }    # $a and $b are not set here
-
+    sub backwards ($$) { $_[1] cmp $_[0]; }  # $a and $b are not set here
+    
     package main;
     @new = sort other::backwards @old;
-
+    
     # guarantee stability, regardless of algorithm
     use sort 'stable';
     @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
-
+    
     # force use of mergesort (not portable outside Perl 5.8)
     use sort '_mergesort';  # note discouraging _
     @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
 
+Warning: syntactical care is required when sorting the list returned from
+a function. If you want to sort the list returned by the function call
+C<find_records(@key)>, you can use:
+
+    @contact = sort { $a cmp $b } find_records @key;
+    @contact = sort +find_records(@key);
+    @contact = sort &find_records(@key);
+    @contact = sort(find_records(@key));
+
+If instead you want to sort the array @key with the comparison routine
+C<find_records()> then you can use:
+
+    @contact = sort { find_records() } @key;
+    @contact = sort find_records(@key);
+    @contact = sort(find_records @key);
+    @contact = sort(find_records (@key));
+
 If you're using strict, you I<must not> declare $a
 and $b as lexicals.  They are package globals.  That means
-if you're in the C<main> package and type
+that if you're in the C<main> package and type
 
     @articles = sort {$b <=> $a} @files;
 
@@ -5338,22 +5561,22 @@ end of the array.
 
 The following equivalences hold (assuming C<< $[ == 0 and $#a >= $i >> )
 
-    push(@a,$x,$y)     splice(@a,@a,0,$x,$y)
-    pop(@a)            splice(@a,-1)
-    shift(@a)          splice(@a,0,1)
-    unshift(@a,$x,$y)  splice(@a,0,0,$x,$y)
-    $a[$i] = $y                splice(@a,$i,1,$y)
+    push(@a,$x,$y)      splice(@a,@a,0,$x,$y)
+    pop(@a)             splice(@a,-1)
+    shift(@a)           splice(@a,0,1)
+    unshift(@a,$x,$y)   splice(@a,0,0,$x,$y)
+    $a[$i] = $y         splice(@a,$i,1,$y)
 
 Example, assuming array lengths are passed before arrays:
 
-    sub aeq {  # compare two list values
-       my(@a) = splice(@_,0,shift);
-       my(@b) = splice(@_,0,shift);
-       return 0 unless @a == @b;       # same len?
-       while (@a) {
-           return 0 if pop(@a) ne pop(@b);
-       }
-       return 1;
+    sub aeq {  # compare two list values
+        my(@a) = splice(@_,0,shift);
+        my(@b) = splice(@_,0,shift);
+        return 0 unless @a == @b;  # same len?
+        while (@a) {
+            return 0 if pop(@a) ne pop(@b);
+        }
+        return 1;
     }
     if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... }
 
@@ -5370,9 +5593,7 @@ Splits the string EXPR into a list of strings and returns that list.  By
 default, empty leading fields are preserved, and empty trailing ones are
 deleted.  (If all fields are empty, they are considered to be trailing.)
 
-In scalar context, returns the number of fields found and splits into
-the C<@_> array.  Use of split in scalar context is deprecated, however,
-because it clobbers your subroutine arguments.
+In scalar context, returns the number of fields found.
 
 If EXPR is omitted, splits the C<$_> string.  If PATTERN is also omitted,
 splits on whitespace (after skipping any leading whitespace).  Anything
@@ -5394,7 +5615,7 @@ a null pattern C<//>, which is just one member of the set of patterns
 matching a null string) will split the value of EXPR into separate
 characters at each point it matches that way.  For example:
 
-    print join(':', split(/ */, 'hi there'));
+    print join(':', split(/ */, 'hi there')), "\n";
 
 produces the output 'h:i:t:h:e:r:e'.
 
@@ -5403,18 +5624,26 @@ matches only the null string, and is not be confused with the regular use
 of C<//> to mean "the last successful pattern match".  So, for C<split>,
 the following:
 
-    print join(':', split(//, 'hi there'));
+    print join(':', split(//, 'hi there')), "\n";
 
 produces the output 'h:i: :t:h:e:r:e'.
 
-Empty leading (or trailing) fields are produced when there are positive
-width matches at the beginning (or end) of the string; a zero-width match
-at the beginning (or end) of the string does not produce an empty field.
-For example:
+Empty leading fields are produced when there are positive-width matches at
+the beginning of the string; a zero-width match at the beginning of
+the string does not produce an empty field. For example:
 
    print join(':', split(/(?=\w)/, 'hi there!'));
 
-produces the output 'h:i :t:h:e:r:e!'.
+produces the output 'h:i :t:h:e:r:e!'. Empty trailing fields, on the other
+hand, are produced when there is a match at the end of the string (and
+when LIMIT is given and is not 0), regardless of the length of the match.
+For example:
+
+   print join(':', split(//,   'hi there!', -1)), "\n";
+   print join(':', split(/\W/, 'hi there!', -1)), "\n";
+
+produce the output 'h:i: :t:h:e:r:e:!:' and 'hi:there:', respectively,
+both with an empty trailing field.
 
 The LIMIT parameter can be used to split a line partially
 
@@ -5438,7 +5667,7 @@ produces the list value
 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
@@ -5463,7 +5692,7 @@ Example:
         chomp;
         ($login, $passwd, $uid, $gid,
          $gcos, $home, $shell) = split(/:/);
-       #...
+        #...
     }
 
 As with regular pattern matching, any capturing parentheses that are not
@@ -5477,7 +5706,7 @@ X<sprintf>
 
 Returns a string formatted by the usual C<printf> conventions of the C
 library function C<sprintf>.  See below for more details
-and see L<sprintf(3)> or L<printf(3)> on your system for an explanation of
+and see C<sprintf(3)> or C<printf(3)> on your system for an explanation of
 the general principles.
 
 For example:
@@ -5502,36 +5731,36 @@ useful.
 
 Perl's C<sprintf> permits the following universally-known conversions:
 
-   %%  a percent sign
-   %c  a character with the given number
-   %s  a string
-   %d  a signed integer, in decimal
-   %u  an unsigned integer, in decimal
-   %o  an unsigned integer, in octal
-   %x  an unsigned integer, in hexadecimal
-   %e  a floating-point number, in scientific notation
-   %f  a floating-point number, in fixed decimal notation
-   %g  a floating-point number, in %e or %f notation
+   %%    a percent sign
+   %c    a character with the given number
+   %s    a string
+   %d    a signed integer, in decimal
+   %u    an unsigned integer, in decimal
+   %o    an unsigned integer, in octal
+   %x    an unsigned integer, in hexadecimal
+   %e    a floating-point number, in scientific notation
+   %f    a floating-point number, in fixed decimal notation
+   %g    a floating-point number, in %e or %f notation
 
 In addition, Perl permits the following widely-supported conversions:
 
-   %X  like %x, but using upper-case letters
-   %E  like %e, but using an upper-case "E"
-   %G  like %g, but with an upper-case "E" (if applicable)
-   %b  an unsigned integer, in binary
-   %B  like %b, but using an upper-case "B" with the # flag
-   %p  a pointer (outputs the Perl value's address in hexadecimal)
-   %n  special: *stores* the number of characters output so far
+   %X    like %x, but using upper-case letters
+   %E    like %e, but using an upper-case "E"
+   %G    like %g, but with an upper-case "E" (if applicable)
+   %b    an unsigned integer, in binary
+   %B    like %b, but using an upper-case "B" with the # flag
+   %p    a pointer (outputs the Perl value's address in hexadecimal)
+   %n    special: *stores* the number of characters output so far
         into the next variable in the parameter list
 
 Finally, for backward (and we do mean "backward") compatibility, Perl
 permits these unnecessary but widely-supported conversions:
 
-   %i  a synonym for %d
-   %D  a synonym for %ld
-   %U  a synonym for %lu
-   %O  a synonym for %lo
-   %F  a synonym for %f
+   %i    a synonym for %d
+   %D    a synonym for %ld
+   %U    a synonym for %lu
+   %O    a synonym for %lo
+   %F    a synonym for %f
 
 Note that the number of exponent digits in the scientific notation produced
 by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the
@@ -5558,8 +5787,8 @@ to take the arguments out of order, e.g.:
 
 one or more of:
 
-   space   prefix positive number with a space
-   +       prefix positive number with a plus sign
+   space   prefix non-negative number with a space
+   +       prefix non-negative number with a plus sign
    -       left-justify within the field
    0       use zeros, not spaces, to right-justify
    #       ensure the leading "0" for any octal,
@@ -5723,9 +5952,9 @@ installation. (This requires that either the platform natively supports quads
 or Perl was specifically compiled to support quads.) You can find out
 whether your Perl supports quads via L<Config>:
 
-       use Config;
-       ($Config{use64bitint} eq 'define' || $Config{longsize} >= 8) &&
-               print "quads\n";
+    use Config;
+    ($Config{use64bitint} eq 'define' || $Config{longsize} >= 8) &&
+        print "quads\n";
 
 For floating point conversions (C<e f g E F G>), numbers are usually assumed
 to be the default floating point size on your platform (double or long double),
@@ -5733,8 +5962,8 @@ but you can force 'long double' with C<q>, C<L>, or C<ll> if your
 platform supports them. You can find out whether your Perl supports long
 doubles via L<Config>:
 
-       use Config;
-       $Config{d_longdbl} eq 'define' && print "long doubles\n";
+    use Config;
+    $Config{d_longdbl} eq 'define' && print "long doubles\n";
 
 You can find out whether Perl considers 'long double' to be the default
 floating point size to use on your platform via L<Config>:
@@ -5772,7 +6001,7 @@ So:
 would use C<$a> for the width, C<$b> for the precision and C<$c>
 as the value to format, while:
 
-  print '<%*1$.*s>', $a, $b;
+  printf '<%*1$.*s>', $a, $b;
 
 would use C<$a> for the width and the precision, and C<$b> as the
 value to format.
@@ -5780,10 +6009,10 @@ value to format.
 Here are some more examples - beware that when using an explicit
 index, the C<$> may need to be escaped:
 
-  printf "%2\$d %d\n",    12, 34;              # will print "34 12\n"
-  printf "%2\$d %d %d\n", 12, 34;              # will print "34 12 34\n"
-  printf "%3\$d %d %d\n", 12, 34, 56;          # will print "56 12 34\n"
-  printf "%2\$*3\$d %d\n", 12, 34, 3;          # will print " 34 12\n"
+  printf "%2\$d %d\n",    12, 34;        # will print "34 12\n"
+  printf "%2\$d %d %d\n", 12, 34;        # will print "34 12 34\n"
+  printf "%3\$d %d %d\n", 12, 34, 56;    # will print "56 12 34\n"
+  printf "%2\$*3\$d %d\n", 12, 34, 3;    # will print " 34 12\n"
 
 =back
 
@@ -5851,7 +6080,7 @@ than the default seed.  Checksumming the compressed output of one or more
 rapidly changing operating system status programs is the usual method.  For
 example:
 
-    srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
+    srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip -f`);
 
 If you're particularly concerned with this, see the C<Math::TrulyRandom>
 module in CPAN.
@@ -5912,7 +6141,7 @@ stat is done, but the current contents of the stat structure from the
 last C<stat>, C<lstat>, or filetest are returned.  Example:
 
     if (-x $file && (($d) = stat(_)) && $d < 0) {
-       print "$file is executable NFS file\n";
+        print "$file is executable NFS file\n";
     }
 
 (This works on machines only for which the device number is negative
@@ -5934,8 +6163,8 @@ The L<File::stat> module provides a convenient, by-name access mechanism:
     use File::stat;
     $sb = stat($filename);
     printf "File is %s, size is %s, perm %04o, mtime %s\n",
-       $filename, $sb->size, $sb->mode & 07777,
-       scalar localtime $sb->mtime;
+           $filename, $sb->size, $sb->mode & 07777,
+           scalar localtime $sb->mtime;
 
 You can import symbolic mode constants (C<S_IF*>) and functions
 (C<S_IS*>) from the Fcntl module:
@@ -5977,11 +6206,11 @@ The commonly available C<S_IF*> constants are
 
 and the C<S_IF*> functions are
 
-    S_IMODE($mode)     the part of $mode containing the permission bits
-                       and the setuid/setgid/sticky bits
+    S_IMODE($mode)    the part of $mode containing the permission bits
+            and the setuid/setgid/sticky bits
 
-    S_IFMT($mode)      the part of $mode containing the file type
-                       which can be bit-anded with e.g. S_IFREG
+    S_IFMT($mode)    the part of $mode containing the file type
+            which can be bit-anded with e.g. S_IFREG
                         or with the following functions
 
     # The operators -f, -d, -l, -b, -c, -p, and -S.
@@ -6041,12 +6270,12 @@ For example, here is a loop that inserts index producing entries
 before any line containing a certain pattern:
 
     while (<>) {
-       study;
-       print ".IX foo\n"       if /\bfoo\b/;
-       print ".IX bar\n"       if /\bbar\b/;
-       print ".IX blurfl\n"    if /\bblurfl\b/;
-       # ...
-       print;
+        study;
+        print ".IX foo\n"    if /\bfoo\b/;
+        print ".IX bar\n"    if /\bbar\b/;
+        print ".IX blurfl\n" if /\bblurfl\b/;
+        # ...
+        print;
     }
 
 In searching for C</\bfoo\b/>, only those locations in C<$_> that contain C<f>
@@ -6065,15 +6294,15 @@ out the names of those files that contain a match:
 
     $search = 'while (<>) { study;';
     foreach $word (@words) {
-       $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
+        $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
     }
     $search .= "}";
     @ARGV = @files;
     undef $/;
-    eval $search;              # this screams
-    $/ = "\n";         # put back to normal input delimiter
+    eval $search;        # this screams
+    $/ = "\n";        # put back to normal input delimiter
     foreach $file (sort keys(%seen)) {
-       print $file, "\n";
+        print $file, "\n";
     }
 
 =item sub NAME BLOCK
@@ -6109,11 +6338,11 @@ everything to the end of the string.  If LENGTH is negative, leaves that
 many characters off the end of the string.
 
     my $s = "The black cat climbed the green tree";
-    my $color  = substr $s, 4, 5;      # black
-    my $middle = substr $s, 4, -11;    # black cat climbed the
-    my $end    = substr $s, 14;                # climbed the green tree
-    my $tail   = substr $s, -4;                # tree
-    my $z      = substr $s, -4, 2;     # tr
+    my $color  = substr $s, 4, 5;      # black
+    my $middle = substr $s, 4, -11;    # black cat climbed the
+    my $end    = substr $s, 14;        # climbed the green tree
+    my $tail   = substr $s, -4;        # tree
+    my $z      = substr $s, -4, 2;     # tr
 
 You can use the substr() function as an lvalue, in which case EXPR
 must itself be an lvalue.  If you assign something shorter than LENGTH,
@@ -6129,10 +6358,10 @@ substring that is entirely outside the string is a fatal error.
 Here's an example showing the behavior for boundary cases:
 
     my $name = 'fred';
-    substr($name, 4) = 'dy';           # $name is now 'freddy'
-    my $null = substr $name, 6, 2;     # returns '' (no warning)
-    my $oops = substr $name, 7;                # returns undef, with warning
-    substr($name, 7) = 'gap';          # fatal error
+    substr($name, 4) = 'dy';         # $name is now 'freddy'
+    my $null = substr $name, 6, 2;   # returns '' (no warning)
+    my $oops = substr $name, 7;      # returns undef, with warning
+    substr($name, 7) = 'gap';        # fatal error
 
 An alternative to using substr() as an lvalue is to specify the
 replacement string as the 4th argument.  This allows you to replace
@@ -6140,7 +6369,7 @@ parts of the EXPR and return what was there before in one operation,
 just as you can with splice().
 
     my $s = "The black cat climbed the green tree";
-    my $z = substr $s, 14, 7, "jumped from";   # climbed
+    my $z = substr $s, 14, 7, "jumped from";    # climbed
     # $s is now "The black cat jumped from the green tree"
 
 Note that the lvalue returned by the 3-arg version of substr() acts as
@@ -6149,10 +6378,10 @@ of the original string is being modified; for example:
 
     $x = '1234';
     for (substr($x,1,2)) {
-        $_ = 'a';   print $x,"\n";     # prints 1a4
-        $_ = 'xyz'; print $x,"\n";     # prints 1xyz4
+        $_ = 'a';   print $x,"\n";    # prints 1a4
+        $_ = 'xyz'; print $x,"\n";    # prints 1xyz4
         $x = '56789';
-        $_ = 'pq';  print $x,"\n";     # prints 5pq9
+        $_ = 'pq';  print $x,"\n";    # prints 5pq9
     }
 
 Prior to Perl version 5.9.1, the result of using an lvalue multiple times was
@@ -6185,7 +6414,7 @@ integer arguments are not literals and have never been interpreted in a
 numeric context, you may need to add C<0> to them to force them to look
 like numbers.  This emulates the C<syswrite> function (or vice versa):
 
-    require 'syscall.ph';              # may need to run h2ph
+    require 'syscall.ph';        # may need to run h2ph
     $s = "hi there\n";
     syscall(&SYS_write, fileno(STDOUT), $s, length $s);
 
@@ -6309,9 +6538,9 @@ POSITION, and C<2> to set it to EOF plus POSITION (typically
 negative).
 
 Note the I<in bytes>: even if the filehandle has been set to operate
-on characters (for example by using the C<:utf8> I/O layer), tell()
-will return byte offsets, not character offsets (because implementing
-that would render sysseek() very slow).
+on characters (for example by using the C<:encoding(utf8)> I/O layer),
+tell() will return byte offsets, not character offsets (because
+implementing that would render sysseek() very slow).
 
 sysseek() bypasses normal buffered IO, so mixing this with reads (other
 than C<sysread>, for example C<< <> >> or read()) C<print>, C<write>,
@@ -6322,8 +6551,8 @@ and C<SEEK_END> (start of the file, current position, end of the file)
 from the Fcntl module.  Use of the constants is also more portable
 than relying on 0, 1, and 2.  For example to define a "systell" function:
 
-       use Fcntl 'SEEK_CUR';
-       sub systell { sysseek($_[0], 0, SEEK_CUR) }
+    use Fcntl 'SEEK_CUR';
+    sub systell { sysseek($_[0], 0, SEEK_CUR) }
 
 Returns the new position, or the undefined value on failure.  A position
 of zero is returned as the string C<"0 but true">; thus C<sysseek> returns
@@ -6363,6 +6592,9 @@ C<qx//>, as described in L<perlop/"`STRING`">.  Return value of -1
 indicates a failure to start the program or an error of the wait(2) system
 call (inspect $! for the reason).
 
+If you'd like to make C<system> (and many other bits of Perl) die on error,
+have a look at the L<autodie> pragma.
+
 Like C<exec>, C<system> allows you to lie to a program about its name if
 you use the C<system PROGRAM LIST> syntax.  Again, see L</exec>.
 
@@ -6373,20 +6605,20 @@ value.
 
     @args = ("command", "arg1", "arg2");
     system(@args) == 0
-        or die "system @args failed: $?"
+        or die "system @args failed: $?"
 
-You can check all the failure possibilities by inspecting
-C<$?> like this:
+If you'd like to manually inspect C<system>'s failure, you can check all
+possible failure modes by inspecting C<$?> like this:
 
     if ($? == -1) {
-       print "failed to execute: $!\n";
+        print "failed to execute: $!\n";
     }
     elsif ($? & 127) {
-       printf "child died with signal %d, %s coredump\n",
-           ($? & 127),  ($? & 128) ? 'with' : 'without';
+        printf "child died with signal %d, %s coredump\n",
+            ($? & 127),  ($? & 128) ? 'with' : 'without';
     }
     else {
-       printf "child exited with value %d\n", $? >> 8;
+        printf "child exited with value %d\n", $? >> 8;
     }
 
 Alternatively you might inspect the value of C<${^CHILD_ERROR_NATIVE}>
@@ -6436,9 +6668,9 @@ the actual filehandle.  If FILEHANDLE is omitted, assumes the file
 last read.
 
 Note the I<in bytes>: even if the filehandle has been set to
-operate on characters (for example by using the C<:utf8> open
-layer), tell() will return byte offsets, not character offsets
-(because that would render seek() and tell() rather slow).
+operate on characters (for example by using the C<:encoding(utf8)> open
+layer), tell() will return byte offsets, not character offsets (because
+that would render seek() and tell() rather slow).
 
 The return value of tell() for the standard streams like the STDIN
 depends on the operating system: it may return -1 or something else.
@@ -6479,7 +6711,7 @@ C<each> function to iterate over such.  Example:
     use NDBM_File;
     tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
     while (($key,$val) = each %HIST) {
-       print $key, ' = ', unpack('L',$val), "\n";
+        print $key, ' = ', unpack('L',$val), "\n";
     }
     untie(%HIST);
 
@@ -6591,7 +6823,8 @@ Note that times for children are included only after they terminate.
 
 =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>
@@ -6615,14 +6848,15 @@ X<uc> X<uppercase> X<toupper>
 =item uc
 
 Returns an uppercased version of EXPR.  This is the internal function
-implementing the C<\U> escape in double-quoted strings.  Respects
-current LC_CTYPE locale if C<use locale> in force.  See L<perllocale>
-and L<perlunicode> for more details about locale and Unicode support.
+implementing the C<\U> escape in double-quoted strings.
 It does not attempt to do titlecase mapping on initial letters.  See
 C<ucfirst> for that.
 
 If EXPR is omitted, uses C<$_>.
 
+This function behaves the same way under various pragma, such as in a locale,
+as L</lc> does.
+
 =item ucfirst EXPR
 X<ucfirst> X<uppercase>
 
@@ -6630,12 +6864,13 @@ X<ucfirst> X<uppercase>
 
 Returns the value of EXPR with the first character in uppercase
 (titlecase in Unicode).  This is the internal function implementing
-the C<\u> escape in double-quoted strings.  Respects current LC_CTYPE
-locale if C<use locale> in force.  See L<perllocale> and L<perlunicode>
-for more details about locale and Unicode support.
+the C<\u> escape in double-quoted strings.
 
 If EXPR is omitted, uses C<$_>.
 
+This function behaves the same way under various pragma, such as in a locale,
+as L</lc> does.
+
 =item umask EXPR
 X<umask>
 
@@ -6706,20 +6941,29 @@ X<unlink> X<delete> X<remove> X<rm> X<del>
 
 =item unlink
 
-Deletes a list of files.  Returns the number of files successfully
-deleted.
+Deletes a list of files. On success, it returns the number of files
+it successfully deleted. On failure, it returns false and sets C<$!>
+(errno):
 
-    $cnt = unlink 'a', 'b', 'c';
+    my $unlinked = unlink 'a', 'b', 'c';
     unlink @goners;
-    unlink <*.bak>;
+    unlink glob "*.bak";
+
+On error, C<unlink> will not tell you which files it could not remove.
+If you want to know which files you could not remove, try them one
+at a time:
 
-Note: C<unlink> will not attempt to delete directories unless you are superuser
-and the B<-U> flag is supplied to Perl.  Even if these conditions are
-met, be warned that unlinking a directory can inflict damage on your
-filesystem.  Finally, using C<unlink> on directories is not supported on 
-many operating systems.  Use C<rmdir> instead.
+     foreach my $file ( @goners ) {
+         unlink $file or warn "Could not unlink $file: $!";
+         }
 
-If LIST is omitted, uses C<$_>.
+Note: C<unlink> will not attempt to delete directories unless you are
+superuser and the B<-U> flag is supplied to Perl. Even if these
+conditions are met, be warned that unlinking a directory can inflict
+damage on your filesystem.  Finally, using C<unlink> on directories is
+not supported on many operating systems.  Use C<rmdir> instead.
+
+If LIST is omitted, C<unlink> uses C<$_>.
 
 =item unpack TEMPLATE,EXPR
 X<unpack>
@@ -6730,7 +6974,9 @@ C<unpack> does the reverse of C<pack>: it takes a string
 and expands it out into a list of values.
 (In scalar context, it returns merely the first value produced.)
 
-If EXPR is omitted, unpacks the C<$_> string.
+If EXPR is omitted, unpacks the C<$_> string. for an introduction to this function.
+
+See L<perlpacktut> for an introduction to this function.
 
 The string is broken into chunks described by the TEMPLATE.  Each chunk
 is converted separately to a value.  Typically, either the string is a result
@@ -6741,8 +6987,8 @@ The TEMPLATE has the same format as in the C<pack> function.
 Here's a subroutine that does substring:
 
     sub substr {
-       my($what,$where,$howmuch) = @_;
-       unpack("x$where a$howmuch", $what);
+        my($what,$where,$howmuch) = @_;
+        unpack("x$where a$howmuch", $what);
     }
 
 and then there's
@@ -6760,8 +7006,8 @@ For example, the following
 computes the same number as the System V sum program:
 
     $checksum = do {
-       local $/;  # slurp!
-       unpack("%32W*",<>) % 65535;
+        local $/;  # slurp!
+        unpack("%32W*",<>) % 65535;
     };
 
 The following efficiently counts the number of set bits in a bit vector:
@@ -6816,7 +7062,7 @@ Imports some semantics into the current package from the named module,
 generally by aliasing certain subroutine or variable names into your
 package.  It is exactly equivalent to
 
-    BEGIN { require Module; import Module LIST; }
+    BEGIN { require Module; Module->import( LIST ); }
 
 except that Module I<must> be a bareword.
 
@@ -6831,20 +7077,23 @@ of perl older than the specified one.
 
 Specifying VERSION as a literal of the form v5.6.1 should generally be
 avoided, because it leads to misleading error messages under earlier
-versions of Perl that do not support this syntax.  The equivalent numeric
-version should be used instead.
+versions of Perl (that is, prior to 5.6.0) that do not support this
+syntax.  The equivalent numeric version should be used instead.
 
-    use v5.6.1;                # compile time version check
-    use 5.6.1;         # ditto
-    use 5.006_001;     # ditto; preferred for backwards compatibility
+    use v5.6.1;     # compile time version check
+    use 5.6.1;      # ditto
+    use 5.006_001;  # ditto; preferred for backwards compatibility
 
 This is often useful if you need to check the current Perl version before
-C<use>ing library modules that have changed in incompatible ways from
-older versions of Perl.  (We try not to do this more than we have to.)
+C<use>ing library modules that won't work with older versions of Perl.
+(We try not to do this more than we have to.)
 
 Also, if the specified perl version is greater than or equal to 5.9.5,
 C<use VERSION> will also load the C<feature> pragma and enable all
 features available in the requested version.  See L<feature>.
+Similarly, if the specified perl version is greater than or equal to
+5.11.0, strictures are enabled lexically as with C<use strict> (except
+that the F<strict.pm> file is not actually loaded).
 
 The C<BEGIN> forces the C<require> and C<import> to happen at compile time.  The
 C<require> makes sure the module is loaded into memory if it hasn't been
@@ -6893,6 +7142,15 @@ block scope (like C<strict> or C<integer>, unlike ordinary modules,
 which import symbols into the current package (which are effective
 through the end of the file).
 
+Because C<use> takes effect at compile time, it doesn't respect the
+ordinary flow control of the code being compiled.  In particular, putting
+a C<use> inside the false branch of a conditional doesn't prevent it
+from being processed.  If a module or pragma needs to be loaded only
+conditionally, this can be done using the L<if> pragma:
+
+    use if $] < 5.008, "utf8";
+    use if WANT_WARNINGS, warnings => qw(all);
+
 There's a corresponding C<no> command that unimports meanings imported
 by C<use>, i.e., it calls C<unimport Module LIST> instead of C<import>.
 It behaves exactly as C<import> does with respect to VERSION, an
@@ -6950,8 +7208,10 @@ file names.
 =item values HASH
 X<values>
 
-Returns a list consisting of all the values of the named hash.
-(In a scalar context, returns the number of values.)
+=item values ARRAY
+
+Returns a list consisting of all the values of the named hash, or the values
+of an array. (In a scalar context, returns the number of values.)
 
 The values are returned in an apparently random order.  The actual
 random order is subject to change in future versions of perl, but it
@@ -6960,14 +7220,20 @@ function would produce on the same (unmodified) hash.  Since Perl
 5.8.1 the ordering is different even between different runs of Perl
 for security reasons (see L<perlsec/"Algorithmic Complexity Attacks">).
 
-As a side effect, calling values() resets the HASH's internal iterator,
+As a side effect, calling values() resets the HASH or ARRAY's internal
+iterator,
 see L</each>. (In particular, calling values() in void context resets
-the iterator with no other overhead.)
+the iterator with no other overhead. Apart from resetting the iterator,
+C<values @array> in list context is no different to plain C<@array>.
+We recommend that you use void context C<keys @array> for this, but reasoned
+that it taking C<values @array> out would require more documentation than
+leaving it in.)
+
 
 Note that the values are not copied, which means modifying them will
 modify the contents of the hash:
 
-    for (values %hash)             { s/foo/bar/g }   # modifies %hash values
+    for (values %hash)      { s/foo/bar/g }   # modifies %hash values
     for (@hash{keys %hash}) { s/foo/bar/g }   # same
 
 See also C<keys>, C<each>, and C<sort>.
@@ -7021,22 +7287,22 @@ The comments show the string after each step.  Note that this code works
 in the same way on big-endian or little-endian machines.
 
     my $foo = '';
-    vec($foo,  0, 32) = 0x5065726C;    # 'Perl'
+    vec($foo,  0, 32) = 0x5065726C; # 'Perl'
 
     # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits
-    print vec($foo, 0, 8);             # prints 80 == 0x50 == ord('P')
-
-    vec($foo,  2, 16) = 0x5065;                # 'PerlPe'
-    vec($foo,  3, 16) = 0x726C;                # 'PerlPerl'
-    vec($foo,  8,  8) = 0x50;          # 'PerlPerlP'
-    vec($foo,  9,  8) = 0x65;          # 'PerlPerlPe'
-    vec($foo, 20,  4) = 2;             # 'PerlPerlPe'   . "\x02"
-    vec($foo, 21,  4) = 7;             # 'PerlPerlPer'
-                                        # 'r' is "\x72"
-    vec($foo, 45,  2) = 3;             # 'PerlPerlPer'  . "\x0c"
-    vec($foo, 93,  1) = 1;             # 'PerlPerlPer'  . "\x2c"
-    vec($foo, 94,  1) = 1;             # 'PerlPerlPerl'
-                                        # 'l' is "\x6c"
+    print vec($foo, 0, 8);  # prints 80 == 0x50 == ord('P')
+
+    vec($foo,  2, 16) = 0x5065; # 'PerlPe'
+    vec($foo,  3, 16) = 0x726C; # 'PerlPerl'
+    vec($foo,  8,  8) = 0x50;   # 'PerlPerlP'
+    vec($foo,  9,  8) = 0x65;   # 'PerlPerlPe'
+    vec($foo, 20,  4) = 2;      # 'PerlPerlPe'   . "\x02"
+    vec($foo, 21,  4) = 7;      # 'PerlPerlPer'
+                                   # 'r' is "\x72"
+    vec($foo, 45,  2) = 3;      # 'PerlPerlPer'  . "\x0c"
+    vec($foo, 93,  1) = 1;      # 'PerlPerlPer'  . "\x2c"
+    vec($foo, 94,  1) = 1;      # 'PerlPerlPerl'
+                                   # 'l' is "\x6c"
 
 To transform a bit vector into a string or list of 0's and 1's, use these:
 
@@ -7216,7 +7482,7 @@ X<wait>
 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>.
 
@@ -7226,12 +7492,12 @@ X<waitpid>
 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";
     #...
     do {
-       $kid = waitpid(-1, WNOHANG);
+        $kid = waitpid(-1, WNOHANG);
     } while $kid > 0;
 
 then you can do a non-blocking wait for all pending zombie processes.
@@ -7253,7 +7519,7 @@ C<eval> is looking for a list value.  Returns false if the context is
 looking for a scalar.  Returns the undefined value if the context is
 looking for no value (void context).
 
-    return unless defined wantarray;   # don't bother doing more
+    return unless defined wantarray; # don't bother doing more
     my @a = complex_calculation();
     return wantarray ? @a : "@a";
 
@@ -7270,7 +7536,7 @@ Prints the value of LIST to STDERR.  If the last element of LIST does
 not end in a newline, it appends the same file/line number text as C<die>
 does.
 
-If LIST is empty and C<$@> already contains a value (typically from a
+If the output is empty and C<$@> already contains a value (typically from a
 previous eval) that value is used after appending C<"\t...caught">
 to C<$@>.  This is useful for staying almost, but not entirely similar to
 C<die>.
@@ -7341,6 +7607,7 @@ Note that write is I<not> the opposite of C<read>.  Unfortunately.
 
 =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