in reply to Re: Out of memory problem when copying contents of file into array (Benchmarks)
in thread Out of memory problem when copying contents of file into array

'OP\'s' => sub { my $lineno = 100; open( FILE, "$f" ) or die "Can't find $f\n"; my @lines = <FILE>; my $num = @lines; for ( ; $lineno > 0 ; $lineno-- ) { my @tail = @lines[ $num - $lineno ]; } close(FILE); },
This can't be correct. You never create an array with 100 lines. You do create 100 arrays with one line each, using a single element slice ('use warnings' complains).
'`tail -100`' => sub { my @lines = split( /\n/, `tail -100 $f` ); },
Why the explicite splitting? Why not just
my @lines = `tail -100 $f`;
Not that it makes a huge difference speedwise.

Replies are listed 'Best First'.
Re^3: Out of memory problem when copying contents of file into array (Benchmarks)
by bpphillips (Friar) on Feb 18, 2005 at 17:39 UTC
    I didn't write it... I just copied it from the OP's post. On even a cursory look, it's obviously broken but I didn't do that when I was setting up the Benchmark. My mistake.