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
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).'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); },
Why the explicite splitting? Why not just'`tail -100`' => sub { my @lines = split( /\n/, `tail -100 $f` ); },
Not that it makes a huge difference speedwise.my @lines = `tail -100 $f`;
|
|---|
| 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 |