in reply to Iterating through file to find specific subsets of lines
use warnings; use strict; my @lines = <DATA>; my @pos; foreach my $line (@lines) { chomp $line; my @columns = split( /\s+/, $line ); my $score = $columns[1]; if ($score < 50) { push @pos, $columns[0]; } else { print "@pos[0, -1]\n" if @pos; @pos = (); } } print "@pos[0, -1]\n" if @pos; __DATA__ 1 50 2 50 3 1 4 10 5 49 6 8 7 50 8 5 9 5 10 40
Note: I changed \t to \s+ just to create a self-contained example.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Iterating through file to find specific subsets of lines
by thegirlm0nkey (Initiate) on Dec 04, 2013 at 15:35 UTC |