My first reaction was to split and grep, but since the numbers are so tightly defined, I think a regex should do,
The while (/(foo)/g) construction loops over all the matches, putting the matching text in $1.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 $!;
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
In reply to Re: Seeking Algorithm
by Zaxo
in thread Seeking Algorithm
by WhiteBird
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |