Thanks for the code tag change! Now I can read it. Evidently, you do not need the 2nd arg in the split(), my memory was faulty, Ooops.
When you add in the $SIZE comparison, you need to do something about the line that is not numeric (the first header line) - otherwise the comparison will fail with "$SIZE not numeric". You could read and deal with that first line before the loop or below I added a test in the "if" to check that it is numeric before doing the comparison. In the "if" if $SIZE doesn't start with 0-9 or the "minus sign" or period, then rest of the "if" is skipped and the line is printed.
I usually add a "skip blank" line statement in these things as sometimes there is a trailing blank line that causes trouble- that's purely optional.
#!usr/bin/perl -w
use strict;
while(<DATA>)
{
next if /^\s$/; # skip blank lines
my ($SAMPLE_NAME, $SIZE) = (split /\s+/)[1,3];
# print line if $SIZE isn't numeric, e.g. "SIZE"
# or if it is a number, then must meet min, max criteria
if ($SIZE =~ /^[^0-9-.]/ or ( $SIZE > 2 and $SIZE <5))
{
print "$SAMPLE_NAME $SIZE\n";
}
}
=prints
SAMPLE_NAME SIZE
U7345 4.333
=cut
__DATA__
ID SAMPLE_NAME EFFECTS SIZE
001 U7654 NEGATIVE 5.666
002 U7345 POSITIVE 4.333
003 U7674 NEGATIVE 1.696
002 U7845 POSITIVE -4.333
|