Changeset 13649 for docs/Perl6/Spec

Show
Ignore:
Timestamp:
09/26/06 02:17:04 (2 years ago)
Author:
lwall
Message:

Whacked on .slurp vs .lines doc.
De-P5ified a bit of the IO doc.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • docs/Perl6/Spec/IO.pod

    r13388 r13649  
    1212 Contributions: Mark Stosberg <mark@summersault.com> 
    1313 Date:          12 Sep 2006 
    14  Last Modified: 17 Sep 2006 
    15  Version:       14   
     14 Last Modified: 25 Sep 2006 
     15 Version:       15   
    1616 
    1717This is a draft document. Many of these functions will work as in Perl 5, 
     
    4343A file test, where X is one of the letters listed below.  This unary 
    4444operator takes one argument, either a filename or a filehandle, and 
    45 tests the associated file to see if something is true about it.  If the 
    46 argument is omitted, tests C<$_>, except for C<-t>, which tests STDIN. 
    47 Unless otherwise documented, it returns C<1> for true and C<''> for false, or 
    48 the undefined value if the file doesn't exist.  Despite the funny 
     45tests the associated file to see if something is true about it. 
     46The argument may not be omitted unless it is C<$_>, in which case you must 
     47use the C<.'-X'> form. 
     48 
     49All file test operators return a stat buffer that also carries a "cumulative 
     50success" boolean (or file size in the case of C<-s>) so that tests may be stacked: 
     51 
     52    -r -w $filename 
     53 
     54or applied to existing stat buffers: 
     55 
     56    $b = stat($filename); 
     57    if -r $b {...} 
     58 
     59Despite the funny 
    4960names, precedence is the same as any other named unary operator, and 
    5061the argument may be parenthesized like any other unary operator.  The 
     
    140151list must be the numerical mode, which should probably be an octal 
    141152number, and which definitely should I<not> be a string of octal digits: 
    142 C<0644> is okay, C<'0644'> is not.  Returns the number of files 
    143 successfully changed.  See also L</oct>, if all you have is a string. 
    144  
    145     $cnt = chmod 0755, 'foo', 'bar'; 
    146     chmod 0755, @executables; 
    147     $mode = '0644'; chmod $mode, 'foo';      # !!! sets mode to 
    148                                              # --w----r-T 
    149     $mode = '0644'; chmod oct($mode), 'foo'; # this is better 
    150     $mode = 0644;   chmod $mode, 'foo';      # this is best 
     153C<0o644> is okay, C<0644> is not.  Returns the number of files 
     154successfully changed. 
     155 
     156    $cnt = chmod 0o755, 'foo', 'bar'; 
     157    chmod 0o755, @executables; 
     158    $mode = '0644'; chmod $mode, 'foo';      # !!! sets mode to --w----r-T 
     159    $mode = '0o644'; chmod $mode, 'foo';     # this is better 
     160    $mode = 0o644;   chmod $mode, 'foo';     # this is best 
    151161 
    152162=item close FILEHANDLE 
     
    197207=item lstat 
    198208 
     209Returns a stat buffer.  If the lstat succeeds, the stat buffer evaluates 
     210to true, and additional file tests may be performed on the value.  If 
     211the stat fails, all subsequent tests on the stat buffer also evaluate 
     212to false. 
     213 
    199214=item mkdir 
    200215 
     
    251266 
    252267=item stat 
     268 
     269Returns a stat buffer.  If the lstat succeeds, the stat buffer evaluates 
     270to true, and additional file tests may be performed on the value.  If 
     271the stat fails, all subsequent tests on the stat buffer also evaluate 
     272to false. 
    253273 
    254274=item symlink 
     
    366386=item binmode 
    367387 
     388=item lines 
     389 
     390    our List multi method lines (IO $handle:) is export; 
     391    our List multi lines (Str $filename); 
     392 
     393Returns all the lines of a file as a (lazy) List regardless of context. 
     394See also C<slurp>. 
     395 
    368396=item pipe 
    369397 
     
    389417 
    390418=item slurp 
     419 
     420    our Item multi method slurp (IO $handle: *%opts) is export; 
     421    our Item multi slurp (Str $filename, *%opts); 
     422 
     423Slurps the entire file into a Str or Buf regardless of context. 
     424(See also C<lines>.)  Whether a Str or Buf is returneded depends on 
     425the options. 
    391426 
    392427=item socket