如何在Perl中的正则表达式匹配后删除该行

nee*_*mie 0 regex perl

我希望在正则表达式匹配后删除该行,但我不确定如何编写删除Perl中的下一行 - 帮助?

while ( my $line = <FILE> ) {
if ($line =~ m/(regex)/i) {
# delete the next $line
}    
Run Code Online (Sandbox Code Playgroud)

And*_*ter 7

你是什​​么意思"删除"?你的意思是忽略它?

while ( my $line = <FILE> ) {
    if ( $line =~ /regex/ ) {  # If it matches this regex
        my $ignored = <FILE>;  # read the next line and ignore it.
    }
}
Run Code Online (Sandbox Code Playgroud)

  • @neemie这就是`$ ignored`无所事事.你会读到另一行并忽略它.当你回到循环的顶部时,你将在匹配后读取第2行. (2认同)