- 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.
- or download this
open RAMFILE, '<', \$bigstring;
while( <RAMFILE> {
### process in the normal way.
}
- 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 ] );
- 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 ) );
- or download this
#! perl -slw
use strict;
...
# 1,774MB
[16:03:22.93] C:\test>