Как бы вы сделали следующее в perl:
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)/{$1 eq 'winter' ? 'summer' : 'SUMMER'}/gie){
print ".";
}
}
print "\nSeason changed in file $_";
open FILE, ">$file";
print FILE @lines;
close FILE;
}
}