2

I am looping over lines in a file and when matched a particular line, i want to process the lines after the current (matched) line. I can do it :-

open my $fh, '<', "abc" or die "Cannot open!!"; 
while (my $line = <$fh>){
   next if($line !~ m/Important Lines below this Line/);
   last;
}
while (my $line = <$fh>){
   print $line;
}

Is there a better way to do this (code needs to be a part of a bigger perl script) ?

4

1 回答 1

7

我会使用触发器运算符

while(<DATA>) {
    next if 1 .. /Important/;
    print $_;
}
__DATA__
skip
skip
Important Lines below this Line
keep
keep

输出:

keep
keep
于 2013-08-20T07:17:10.797 回答