in reply to Re: Matching on a specific line of text
in thread Matching on a specific line of text

I forgot about the special behaviour of .. in scalar context, when the operands are literal integers. In that case, that value is automatically compared against $.. So my code can be simplified to:
open IN, "<", $file or die "Can't open file $file: $!"; my %data; while(<IN>) { if(1 .. 2) { my($number) = /([\d.]+)\s*$/; $data{$.} = $number; } }

If you need several distinct ranges, you can do

if(1 .. 2 or 6 .. 8) {
as can be demonstrated using the following code:
while(<DATA>) { if(1 .. 2 or 6 .. 8) { print "$.: $_"; } } __DATA__ one two three four five six seven eight nine ten
Result:
1: one
2: two
6: six
7: seven
8: eight
For a single value, you can choose between 4 == $. and 4 .. 4:
if(1 .. 2 or 4 == $. or 6 .. 8) {
if(1 .. 2 or 4 .. 4 or 6 .. 8) {