in reply to Faster push and shift
Try this. It should complete much more quickly unless all the required records are at the beginning of the file:
#! perl -slw use strict; use Data::Dump qw[ pp ]; use Time::HiRes qw[ time ]; use File::ReadBackwards; tie *FH, 'File::ReadBackwards', $ARGV[0] or die $!; my $start = time; my( $last, @a, @b ); while( <FH> ) { /\d+\t(\d+)/; if( $1 > 3 ) { unshift @b, $1; unshift @a, $last; last if @b == 7; } $last = $1; } print time() - $start; print join ' ',times; pp \@a, \@b;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Faster push and shift
by rovf (Priest) on Feb 16, 2012 at 14:05 UTC | |
by choroba (Cardinal) on Feb 16, 2012 at 14:18 UTC | |
by rovf (Priest) on Feb 16, 2012 at 15:08 UTC | |
|
Re^2: Faster push and shift
by locked_user sundialsvc4 (Abbot) on Feb 16, 2012 at 13:57 UTC | |
by BrowserUk (Patriarch) on Feb 16, 2012 at 14:49 UTC |