How would you do the following in 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 ".";
}
}
Updated to show more code, this is what I'm trying to do:
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;
}
}
Just use next
for my $line (@lines) {
next if ($line =~ m/ImportantLineNotToBeChanged/);
if ($line =~ s/SUMMER/WINTER/g){
print ".";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With