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

can add a else{ last } to the if statement so it doesn't bother reading the rest of the file.. Also, if the desired lines are at the beginning, can just do:
my %data; ($data{$_}) = <IN> =~ m/(\d+\.\d+)\s*$/ for 1 .. 2;
(note it's <IN>, not <$file>)

Replies are listed 'Best First'.
Re^3: Matching on a specific line of text
by bart (Canon) on May 07, 2006 at 19:37 UTC
    add a else{ last } to the if statement so it doesn't bother reading the rest of the file.
    Careful if there are holes in your test range... you might jump out of the loop too early. In that case, it's best to do an explicit compare against the maximum line number you're interested in.
    elsif($. > $lastline) { last; }