Keep It Simple, Stupid | |
PerlMonks |
Re^3: Edit lines from a file and replace multiple lines. -- basic english approachby Discipulus (Canon) |
on Mar 29, 2019 at 08:40 UTC ( [id://1231851]=note: print w/replies, xml ) | Need Help?? |
Hello Endurance, > This doesn't work.. ..not even compile ;) A saner indentation will help:
You used too much curlys in your if statements. Then: you didnt follow my approach but instead you are adding to $line and so loosing any notion of the current line that is one of your requirements. As side note if you s/this/that/ is not needed the matching before if $x =~ /this/ because the sostitution only acts if it matches. But let's try to implement (partially: is your work ;) my approach: > Open the file named file.txt. Abort if the file is unreadable. Read the file line per line. If solar wind is found annotate it's line number as solar_linenum Print line just read anyway. Read and print two lines more. If the third line has country then replace it with place and print the line but also set solar_linenum to 0. The same for the other requirement.
HtH L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
In Section
Seekers of Perl Wisdom
|
|