for $line (@lines) { if ($line =~ m/importantlineNottoBeChanged/){ #break out of the for loop,move onto the next line of the file being processed #start the loop again } if ($line =~ s/SUMMER/WINTER/g){ print "."; }}
更新以显示更多代码,这是我正在尝试做的事情:
sub ChangeSeason(){ if (-f and /.log?/) { $file = $_; open file,$file; @lines = <file>; close file; for $line (@lines) { if ($line =~ m/'?Don't touch this line'?/) { last; } if ($line =~ m/'?Or this line'?/){ last; } if ($line =~ m/'?Or this line too'?/){ last; } if ($line +~ m/'?Or this line as well'?/){ last; } if ($line =~ s/(WINTER)/{ eq 'winter' ? 'summer' : 'SUMMER'}/gIE){ print "."; } } print "\nSeason changed in file $_"; open file,">$file"; print file @lines; close file; }}解决方法 只需使用 next
for my $line (@lines) { next if ($line =~ m/importantlineNottoBeChanged/); if ($line =~ s/SUMMER/WINTER/g){ print "."; }}总结
以上是内存溢出为你收集整理的perl if line匹配正则表达式,忽略行并移动到文件中的下一行全部内容,希望文章能够帮你解决perl if line匹配正则表达式,忽略行并移动到文件中的下一行所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)