[BUG:47:LOG] Dropped "and" in pod2man
[p5sagit/p5-mst-13.2.git] / pod / perlfunc.pod
index 25c684a..a28487a 100644 (file)
@@ -108,7 +108,7 @@ delete, each, exists, keys, values
 
 binmode, close, closedir, dbmclose, dbmopen, die, eof,
 fileno, flock, format, getc, print, printf, read, readdir,
-rewinddir, seek, seekdir, select, syscall, sysread,
+rewinddir, seek, seekdir, select, syscall, sysread, sysseek,
 syswrite, tell, telldir, truncate, warn, write
 
 =item Functions for fixed length data or records
@@ -410,13 +410,13 @@ to go back before the current one.
      $hasargs, $wantarray, $evaltext, $is_require) = caller($i);
 
 Here $subroutine may be C<"(eval)"> if the frame is not a subroutine
-call, but C<L<eval>>.  In such a case additional elements $evaltext and
-$is_require are set: $is_require is true if the frame is created by
-C<L<require>> or C<L<use>> statement, $evaltext contains the text of
-C<L<eval EXPR>> statement.  In particular, for C<L<eval BLOCK>>
-statement $filename is C<"(eval)">, but $evaltext is undefined. (Note
-also that C<L<use>> statement creates a C<L<require>> frame inside
-an C<L<eval EXPR>>) frame.
+call, but an C<eval>.  In such a case additional elements $evaltext and
+$is_require are set: $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 a C<eval BLOCK> statement,
+$filename 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.
 
 Furthermore, when called from within the DB package, caller returns more
 detailed information: it sets the list variable @DB::args to be the
@@ -434,7 +434,7 @@ Changes the permissions of a list of files.  The first element of the
 list must be the numerical mode, which should probably be an octal
 number, and which definitely should I<not> a string of octal digits:
 C<0644> is okay, C<'0644'> is not.  Returns the number of files
-successfully changed.  See also L<oct>, if all you have is a string.
+successfully changed.  See also L</oct>, if all you have is a string.
 
     $cnt = chmod 0755, 'foo', 'bar';
     chmod 0755, @executables;
@@ -448,7 +448,7 @@ successfully changed.  See also L<oct>, if all you have is a string.
 
 =item chomp
 
-This is a slightly safer version of chop (see below).  It removes any
+This is a slightly safer version of L</chop>.  It removes any
 line ending that corresponds to the current value of C<$/> (also known as
 $INPUT_RECORD_SEPARATOR in the C<English> module).  It returns the total
 number of characters removed from all its arguments.  It's often used to
@@ -532,7 +532,7 @@ restrictions may be relaxed, but this is not a portable assumption.
 =item chr
 
 Returns the character represented by that NUMBER in the character set.
-For example, C<chr(65)> is "A" in ASCII.  For the reverse, use L<ord>.
+For example, C<chr(65)> is "A" in ASCII.  For the reverse, use L</ord>.
 
 If NUMBER is omitted, uses $_.
 
@@ -551,7 +551,11 @@ omitted, does chroot to $_.
 
 Closes the file or pipe associated with the file handle, returning TRUE
 only if stdio successfully flushes buffers and closes the system file
-descriptor.  You don't have to close FILEHANDLE if you are immediately
+descriptor.  If the file handle came from a piped open C<close> will
+additionally return FALSE if one of the other system calls involved
+fails or if the program exits with non-zero status.  (If the problem was
+that the program exited non-zero $! will be set to 0.)
+You don't have to close FILEHANDLE if you are immediately
 going to do another open() on it, because open() will close it for you.  (See
 open().)  However, an explicit close on an input file resets the line
 counter ($.), while the implicit close done by open() does not.  Also,
@@ -697,7 +701,7 @@ is not guaranteed to produce intuitive results, and should probably be
 avoided.
 
 When used on a hash element, it tells you whether the value is defined,
-not whether the key exists in the hash.  Use L<exists> for the latter
+not whether the key exists in the hash.  Use L</exists> for the latter
 purpose.
 
 Examples:
@@ -741,7 +745,7 @@ again to have memory already ready to be filled.
 This counterintuitive behaviour of defined() on aggregates may be
 changed, fixed, or broken in a future release of Perl.
 
-See also L<undef>, L<exists>, L<ref>.
+See also L</undef>, L</exists>, L</ref>.
 
 =item delete EXPR
 
@@ -1231,7 +1235,7 @@ example:
 See L<perlform> for many details and examples.
 
 
-=item formline PICTURE, LIST
+=item formline PICTURE,LIST
 
 This is an internal function used by C<format>s, though you may call it
 too.  It formats (see L<perlform>) a list of values according to the
@@ -1530,7 +1534,7 @@ actually modifies the element in the original list.
 
 Interprets EXPR as a hex string and returns the corresponding
 value.  (To convert strings that might start with either 0 or 0x
-see L<oct>.)  If EXPR is omitted, uses $_.
+see L</oct>.)  If EXPR is omitted, uses $_.
 
     print hex '0xAf'; # prints '175'
     print hex 'aF';   # same
@@ -1727,7 +1731,7 @@ it succeeded, FALSE otherwise.  See example in L<perlipc/"Sockets: Client/Server
 A local modifies the listed variables to be local to the enclosing block,
 subroutine, C<eval{}>, or C<do>.  If more than one value is listed, the
 list must be placed in parentheses.  See L<perlsub/"Temporary Values via
-local()"> for details.
+local()"> for details, including issues with tied arrays and hashes.
 
 But you really probably want to be using my() instead, because local() isn't
 what most people think of as "local").  See L<perlsub/"Private Variables
@@ -2020,12 +2024,13 @@ The following pairs are more or less equivalent:
 
 See L<perlipc/"Safe Pipe Opens"> for more examples of this.
 
-Explicitly closing any piped filehandle causes the parent process to
-wait for the child to finish, and returns the status value in C<$?>.
-Note: on any operation which may do a fork, unflushed buffers remain
+NOTE: On any operation which may do a fork, unflushed buffers remain
 unflushed in both processes, which means you may need to set C<$|> to
 avoid duplicate output.
 
+Closing any piped filehandle causes the parent process to wait for the
+child to finish, and returns the status value in C<$?>.
+
 Using the constructor from the IO::Handle package (or one of its
 subclasses, such as IO::File or IO::Socket),
 you can generate anonymous filehandles which have the scope of whatever
@@ -2078,7 +2083,7 @@ DIRHANDLEs have their own namespace separate from FILEHANDLEs.
 =item ord
 
 Returns the numeric ascii value of the first character of EXPR.  If
-EXPR is omitted, uses $_.  For the reverse, see L<chr>.
+EXPR is omitted, uses $_.  For the reverse, see L</chr>.
 
 =item pack TEMPLATE,LIST
 
@@ -2096,17 +2101,29 @@ follows:
 
     c  A signed char value.
     C  An unsigned char value.
+
     s  A signed short value.
     S  An unsigned short value.
+         (This 'short' is _exactly_ 16 bits, which may differ from
+          what a local C compiler calls 'short'.)
+
     i  A signed integer value.
     I  An unsigned integer value.
+         (This 'integer' is _at_least_ 32 bits wide.  Its exact size
+          depends on what a local C compiler calls 'int', and may
+          even be larger than the 'long' described in the next item.)
+
     l  A signed long value.
     L  An unsigned long value.
+         (This 'long' is _exactly_ 32 bits, which may differ from
+          what a local C compiler calls 'long'.)
 
-    n  A short in "network" order.
-    N  A long in "network" order.
+    n  A short in "network" (big-endian) order.
+    N  A long in "network" (big-endian) order.
     v  A short in "VAX" (little-endian) order.
     V  A long in "VAX" (little-endian) order.
+         (These 'shorts' and 'longs' are _exactly_ 16 bits and
+          _exactly_ 32 bits, respectively.)
 
     f  A single-precision float in the native format.
     d  A double-precision float in the native format.
@@ -2116,10 +2133,10 @@ follows:
 
     u  A uuencoded string.
 
-    w A BER compressed integer.  Bytes give an unsigned integer base
-      128, most significant digit first, with as few digits as
-      possible, and with the bit 8 of each byte except the last set
-      to "1."
+    w  A BER compressed integer.  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.
@@ -2318,10 +2335,10 @@ If EXPR is omitted, uses $_.
 
 =item rand
 
-Returns a random fractional number between 0 and the value of EXPR.
-(EXPR should be positive.)  If EXPR is omitted, returns a value between
-0 and 1.  Automatically calls srand() unless srand() has already been
-called.  See also srand().
+Returns a random fractional number greater than or equal to 0 and less
+than the value of EXPR.  (EXPR should be positive.)  If EXPR is
+omitted, the value 1 is used.  Automatically calls srand() unless
+srand() has already been called.  See also srand().
 
 (Note: If your rand function consistently returns numbers that are too
 large or too small, then your version of Perl was probably compiled
@@ -2577,26 +2594,30 @@ C<(some expression)> suffices.
 
 =item seek FILEHANDLE,POSITION,WHENCE
 
-Randomly positions the file pointer for FILEHANDLE, just like the fseek()
-call of stdio.  FILEHANDLE may be an expression whose value gives the name
-of the filehandle.  The values for WHENCE are 0 to set the file pointer to
-POSITION, 1 to set the it to current plus POSITION, and 2 to set it to EOF
-plus offset.  You may use the values SEEK_SET, SEEK_CUR, and SEEK_END for
-this from the POSIX module.  Returns 1 upon success, 0 otherwise.
+Sets FILEHANDLE's position, just like the fseek() call of stdio.
+FILEHANDLE may be an expression whose value gives the name of the
+filehandle.  The values for WHENCE are 0 to set the new position to
+POSITION, 1 to set it to the current position plus POSITION, and 2 to
+set it to EOF plus POSITION (typically negative).  For WHENCE you may
+use the constants SEEK_SET, SEEK_CUR, and SEEK_END from either the
+IO::Seekable or the POSIX module.  Returns 1 upon success, 0 otherwise.
+
+If you want to position file for sysread() or syswrite(), don't use
+seek() -- buffering makes its effect on the file's system position
+unpredictable and non-portable.  Use sysseek() instead.
 
 On some systems you have to do a seek whenever you switch between reading
 and writing.  Amongst other things, this may have the effect of calling
-stdio's clearerr(3).  A "whence" of 1 (SEEK_CUR) is useful for not moving
-the file pointer:
+stdio's clearerr(3).  A WHENCE of 1 (SEEK_CUR) is useful for not moving
+the file position:
 
     seek(TEST,0,1);
 
 This is also useful for applications emulating C<tail -f>.  Once you hit
 EOF on your read, and then sleep for a while, you might have to stick in a
-seek() to reset things.  First the simple trick listed above to clear the
-filepointer.  The seek() doesn't change the current position, but it
-I<does> clear the end-of-file condition on the handle, so that the next
-C<E<lt>FILEE<gt>> makes Perl try again to read something.  We hope.
+seek() to reset things.  The seek() doesn't change the current position,
+but it I<does> clear the end-of-file condition on the handle, so that the
+next C<E<lt>FILEE<gt>> makes Perl try again to read something.  We hope.
 
 If that doesn't work (some stdios are particularly cantankerous), then
 you may need something more like this:
@@ -3074,15 +3095,74 @@ L</chomp>, and L</join>.)
 
 =item sprintf FORMAT, LIST
 
-Returns a string formatted by the usual printf conventions of the C
-language.  See L<sprintf(3)> or L<printf(3)> on your system for details.
-(The * character for an indirectly specified length is not
-supported, but you can get the same effect by interpolating a variable
-into the pattern.)  If C<use locale> is
-in effect, the character used for the decimal point in formatted real numbers
-is affected by the LC_NUMERIC locale.  See L<perllocale>.
-Some C libraries' implementations of sprintf() can
-dump core when fed ludicrous arguments.
+Returns a string formatted by the usual printf conventions of the
+C library function sprintf().  See L<sprintf(3)> or L<printf(3)>
+on your system for an explanation of the general principles.
+
+Perl does all of its own sprintf() formatting -- it emulates the C
+function sprintf(), but it doesn't use it (except for floating-point
+numbers, and even then only the standard modifiers are allowed).  As a
+result, any non-standard extensions in your local sprintf() are not
+available from Perl.
+
+Perl's 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
+
+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)
+   %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
+
+Perl permits the following universally-known flags between the C<%>
+and the conversion letter:
+
+   space   prefix positive number with a space
+   +       prefix positive number with a plus sign
+   -       left-justify within the field
+   0       use zeros, not spaces, to right-justify
+   #       prefix octal with "0", hex with "0x"
+   number  minimum field width
+   .number "precision": digits after decimal point for floating-point,
+           max length for string, minimum length for integer
+   l       interpret integer as C type "long" or "unsigned long"
+   h       interpret integer as C type "short" or "unsigned short"
+
+There is also one Perl-specific flag:
+
+   V       interpret integer as Perl's standard integer type
+
+Where a number would appear in the flags, an asterisk ("*") may be
+used instead, in which case Perl uses the next item in the parameter
+list as the given number (that is, as the field width or precision).
+If a field width obtained through "*" is negative, it has the same
+effect as the '-' flag: left-justification.
+
+If C<use locale> is in effect, the character used for the decimal
+point in formatted real numbers is affected by the LC_NUMERIC locale.
+See L<perllocale>.
 
 =item sqrt EXPR
 
@@ -3325,11 +3405,12 @@ into that kind of thing.
 =item sysread FILEHANDLE,SCALAR,LENGTH
 
 Attempts to read LENGTH bytes of data into variable SCALAR from the
-specified FILEHANDLE, using the system call read(2).  It bypasses
-stdio, so mixing this with other kinds of reads may cause confusion.
-Returns the number of bytes actually read, or undef if there was an
-error.  SCALAR will be grown or shrunk so that the last byte actually
-read is the last byte of the scalar after the read.
+specified FILEHANDLE, using the system call read(2).  It bypasses stdio,
+so mixing this with other kinds of reads, print(), write(), seek(), or
+tell() can cause confusion.  Returns the number of bytes actually read,
+or undef if there was an error.  SCALAR will be grown or shrunk so that
+the last byte actually read is the last byte of the scalar after the
+read.
 
 An OFFSET may be specified to place the read data at some place in the
 string other than the beginning.  A negative OFFSET specifies
@@ -3338,6 +3419,23 @@ string.  A positive OFFSET greater than the length of SCALAR results
 in the string being padded to the required size with "\0" bytes before
 the result of the read is appended.
 
+=item sysseek FILEHANDLE,POSITION,WHENCE
+
+Sets FILEHANDLE's system position using the system call lseek(2).  It
+bypasses stdio, so mixing this with reads (other than sysread()),
+print(), write(), seek(), or tell() may cause confusion.  FILEHANDLE may
+be an expression whose value gives the name of the filehandle.  The
+values for WHENCE are 0 to set the new position to POSITION, 1 to set
+the it to the current position plus POSITION, and 2 to set it to EOF
+plus POSITION (typically negative).  For WHENCE, you may use the
+constants SEEK_SET, SEEK_CUR, and SEEK_END from either the IO::Seekable
+or the POSIX module.
+
+Returns the new position, or the undefined value on failure.  A position
+of zero is returned as the string "0 but true"; thus sysseek() returns
+TRUE on success and FALSE on failure, yet you can still easily determine
+the new position.
+
 =item system LIST
 
 Does exactly the same thing as "exec LIST" except that a fork is done
@@ -3388,10 +3486,11 @@ signals and core dumps.
 
 Attempts to write LENGTH bytes of data from variable SCALAR to the
 specified FILEHANDLE, using the system call write(2).  It bypasses
-stdio, so mixing this with prints may cause confusion.  Returns the
-number of bytes actually written, or undef if there was an error.
-If the length is greater than the available data, only as much data as
-is available will be written.
+stdio, so mixing this with reads (other than sysread()), print(),
+write(), seek(), or tell() may cause confusion.  Returns the number of
+bytes actually written, or undef if there was an error.  If the length
+is greater than the available data, only as much data as is available
+will be written.
 
 An OFFSET may be specified to write the data from some part of the
 string other than the beginning.  A negative OFFSET specifies writing
@@ -3401,7 +3500,7 @@ that many bytes counting backwards from the end of the string.
 
 =item tell
 
-Returns the current file position for FILEHANDLE.  FILEHANDLE may be an
+Returns the current position for FILEHANDLE.  FILEHANDLE may be an
 expression whose value gives the name of the actual filehandle.  If
 FILEHANDLE is omitted, assumes the file last read.
 
@@ -3526,7 +3625,7 @@ If EXPR is omitted, uses $_.
 Sets the umask for the process to EXPR and returns the previous value.
 If EXPR is omitted, merely returns the current umask.  Remember that a
 umask is a number, usually given in octal; it is I<not> a string of octal
-digits.  See also L<oct>, if all you have is a string.
+digits.  See also L</oct>, if all you have is a string.
 
 =item undef EXPR
 
@@ -3805,7 +3904,7 @@ examples.
 
 =item write
 
-Writes a formatted record (possibly multiline) to the specified file,
+Writes a formatted record (possibly multi-line) to the specified file,
 using the format associated with that file.  By default the format for
 a file is the one having the same name as the filehandle, but the
 format for the current output channel (see the select() function) may be set