in reply to Seeking Algorithm

My first reaction was to split and grep, but since the numbers are so tightly defined, I think a regex should do,

my @keepers; open my $fh, '<', '/path/to/file.dat' or die $!; while (<$fh>) { while ( /(\d+\.\d+)/g ) { push @keepers, $_ and last if $1 >= 296.1 && $1 <= 314.0; } } close $fh or die $!;
The while (/(foo)/g) construction loops over all the matches, putting the matching text in $1.

Update: Missed the exclusion for 305.1, grep it is:

my @keepers; open my $fh, '<', '/path/to/file.dat' or die $!; while (<$fh>) { my @data = grep { /^\d+\.\d+$/ && $_ >= 296.1 && $_ <= 314.0 } split ','; if (@data) { push @keepers, $_ unless @data == 1 and $data[0] eq '305.1'; } } close $fh or die $!;

Update2: CountZero++ is correct, code amended.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Seeking Algorithm
by CountZero (Bishop) on May 28, 2004 at 10:18 UTC
    Are you sure your updated version works? Some of the data have a 'V' prefixed to the figures and you do not seem to filter this out as you did in your first example.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law