Help for this page

Select Code to Download


  1. or download this
    open FILE, '<', ....;
    my $bigstring;
    do{ local $/; $bigstring = <FILE>; };
    
    ## NOTE: not my $bigstring = do{ local $/; <FILE> }; This consumes dou
    +ble the memory of the above.
    
  2. or download this
    open RAMFILE, '<', \$bigstring;
    while( <RAMFILE> {
        ### process in the normal way.
    }
    
  3. or download this
    my( $p, @index ) = 0;
    
    ...
    ## Then to randomly access line $n of the file
    
    my $nthLine = substr( $bigstring, $index[ $n ], $index[ $n+1 ] - $inde
    +x[ $n ] );
    
  4. or download this
    my( $p, $index ) = ( 0, "\0" );
    vec( $index, ++$p, 32 ) = tell( RAMFILE ) while <RAMFILE>;
    ...
    ## then to randomly access line $n of the file
    
    my $nthLine = substr( $bigstring, vec( $index, $n, 32 ), vec( $index, 
    +$n+1, 32 ) - vec( $index, $n, 32 ) );
    
  5. or download this
    #! perl -slw
    use strict;
    ...
    # 1,774MB
    
    [16:03:22.93] C:\test>