perl 3.0 patch #14 patch #13, continued
[p5sagit/p5-mst-13.2.git] / perl.man.3
index bd64915..35a9c02 100644 (file)
@@ -1,7 +1,17 @@
 ''' Beginning of part 3
-''' $Header: perl.man.3,v 3.0.1.3 89/12/21 20:10:12 lwall Locked $
+''' $Header: perl.man.3,v 3.0.1.5 90/03/12 16:52:21 lwall Locked $
 '''
 ''' $Log:      perl.man.3,v $
+''' Revision 3.0.1.5  90/03/12  16:52:21  lwall
+''' patch13: documented that print $filehandle &foo is ambiguous
+''' patch13: added splice operator: @oldelems = splice(@array,$offset,$len,LIST)
+''' 
+''' Revision 3.0.1.4  90/02/28  18:00:09  lwall
+''' patch9: added pipe function
+''' patch9: documented how to handle arbitrary weird characters in filenames
+''' patch9: documented the unflushed buffers problem on piped opens
+''' patch9: documented how to force top of page
+''' 
 ''' Revision 3.0.1.3  89/12/21  20:10:12  lwall
 ''' patch7: documented that s`pat`repl` does command substitution on replacement
 ''' patch7: documented that $timeleft from select() is likely not implemented
@@ -202,6 +212,22 @@ The following pairs are equivalent:
 .fi
 Explicitly closing any piped filehandle causes the parent process to wait for the
 child to finish, and returns the status value in $?.
+Note: on any operation which may do a fork,
+unflushed buffers remain unflushed in both
+processes, which means you may need to set $| to
+avoid duplicate output.
+.Sp
+The filename that is passed to open will have leading and trailing
+whitespace deleted.
+In order to open a file with arbitrary weird characters in it, it's necessary
+to protect any leading and trailing whitespace thusly:
+.nf
+
+.ne 2
+        $file =~ s#^(\es)#./$1#;
+        open(FOO, "< $file\e0");
+
+.fi
 .Ip "opendir(DIRHANDLE,EXPR)" 8 3
 Opens a directory named EXPR for processing by readdir(), telldir(), seekdir(),
 rewinddir() and closedir().
@@ -270,6 +296,14 @@ Examples:
 
 .fi
 The same template may generally also be used in the unpack function.
+.Ip "pipe(READHANDLE,WRITEHANDLE)" 8 3
+Opens a pair of connected pipes like the corresponding system call.
+Note that if you set up a loop of piped processes, deadlock can occur
+unless you are very careful.
+In addition, note that perl's pipes use stdio buffering, so you may need
+to set $| to flush your WRITEHANDLE after each command, depending on
+the application.
+[Requires version 3.0 patchlevel 9.]
 .Ip "pop(ARRAY)" 8
 .Ip "pop ARRAY" 8 6
 Pops and returns the last value of the array, shortening the array by 1.
@@ -289,6 +323,9 @@ Prints a string or a comma-separated list of strings.
 Returns non-zero if successful.
 FILEHANDLE may be a scalar variable name, in which case the variable contains
 the name of the filehandle, thus introducing one level of indirection.
+(NOTE: If FILEHANDLE is a variable and the next token is a term, it may be
+misinterpreted as an operator unless you interpose a + or put parens around
+the arguments.)
 If FILEHANDLE is omitted, prints by default to standard output (or to the
 last selected output channel\*(--see select()).
 If LIST is also omitted, prints $_ to
@@ -299,6 +336,9 @@ use the select operation.
 Note that, because print takes a LIST, anything in the LIST is evaluated
 in an array context, and any subroutine that you call will have one or more
 of its expressions evaluated in an array context.
+Also be careful not to follow the print keyword with a left parenthesis
+unless you want the corresponding right parenthesis to terminate the
+arguments to the print--interpose a + or put parens around all the arguments.
 .Ip "printf(FILEHANDLE LIST)" 8 10
 .Ip "printf(LIST)" 8
 .Ip "printf FILEHANDLE LIST" 8
@@ -687,13 +727,46 @@ Examples:
                # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
 
 .fi
+.Ip "splice(ARRAY,OFFSET,LENGTH,LIST)" 8 8
+.Ip "splice(ARRAY,OFFSET,LENGTH)" 8
+.Ip "splice(ARRAY,OFFSET)" 8
+Removes the elements designated by OFFSET and LENGTH from an array, and
+replaces them with the elements of LIST, if any.
+Returns the elements removed from the array.
+The array grows or shrinks as necessary.
+If LENGTH is omitted, removes everything from OFFSET onward.
+The following equivalencies hold (assuming $[ == 0):
+.nf
+
+       push(@a,$x,$y)\h'|3.5i'splice(@a,$#x+1,0,$x,$y)
+       pop(@a)\h'|3.5i'splice(@a,-1)
+       shift(@a)\h'|3.5i'splice(@a,0,1)
+       unshift(@a,$x,$y)\h'|3.5i'splice(@a,0,0,$x,$y)
+       $a[$x] = $y\h'|3.5i'splice(@a,$x,1,$y);
+
+Example, assuming array lengths are passed before arrays:
+       
+       sub aeq {       # compare two array values
+               local(@a) = splice(@_,0,shift);
+               local(@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)) { ... }
+
+.fi
 .Ip "split(/PATTERN/,EXPR,LIMIT)" 8 8
 .Ip "split(/PATTERN/,EXPR)" 8 8
 .Ip "split(/PATTERN/)" 8
 .Ip "split" 8
 Splits a string into an array of strings, and returns it.
 (If not in an array context, returns the number of fields found and splits
-into the @_ array.)
+into the @_ array.
+(In an array context, you can force the split into @_
+by using ?? as the pattern delimiters, but it still returns the array value.))
 If EXPR is omitted, splits the $_ string.
 If PATTERN is also omitted, splits on whitespace (/[\ \et\en]+/).
 Anything matching PATTERN is taken to be a delimiter separating the fields.
@@ -1119,11 +1192,14 @@ by assigning the name of the format to the $~ variable.
 .Sp
 Top of form processing is handled automatically:
 if there is insufficient room on the current page for the formatted 
-record, the page is advanced, a special top-of-page format is used
+record, the page is advanced by writing a form feed,
+a special top-of-page format is used
 to format the new page header, and then the record is written.
 By default the top-of-page format is \*(L"top\*(R", but it
 may be set to the
 format of your choice by assigning the name to the $^ variable.
+The number of lines remaining on the current page is in variable $-, which
+can be set to 0 to force a new page.
 .Sp
 If FILEHANDLE is unspecified, output goes to the current default output channel,
 which starts out as