in reply to Re: Matching on a specific line of text
in thread Matching on a specific line of text
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
as can be demonstrated using the following code:if(1 .. 2 or 6 .. 8) {
Result:while(<DATA>) { if(1 .. 2 or 6 .. 8) { print "$.: $_"; } } __DATA__ one two three four five six seven eight nine ten
1: one 2: two 6: six 7: seven 8: eightFor 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) {
|
|---|