in reply to matching a number

If you actually need to extract the number with a regex you can use something like:
while(<F>){ /(\d+\.\d+)/; if (abs($1 - 5.56)<=.1) {print $1,"\n"} }

(If there is more than one number on a line, you'll have to do something a little different, but it looks like that's not the case from your original code.)
chas
(Update: I'm now a little unhappy about this because I noticed that abs(5.56-5.66)<=.1 returns false. I wonder if Test::Number::Delta as suggested by trammell is more reliable in this respect. From the docs it looks like it may not be, but I haven't tried it...)

Replies are listed 'Best First'.
Re^2: matching a number
by davidrw (Prior) on May 31, 2005 at 16:46 UTC
    Minor tweak to make sure the $1 is used IFF the regex succeeds:
    while(<F>){ next unless /(\d+\.\d+)/ && abs($1 - 5.56)<=.1; print $1,"\n"; }