Syntactic Confectionery Delight | |
PerlMonks |
Re^3: Search and replace in all odd linesby johngg (Canon) |
on Jun 25, 2007 at 13:36 UTC ( [id://623170]=note: print w/replies, xml ) | Need Help?? |
perl -i.bak -nle 's/search/replace/g unless $. & 2; print' file
Your one-liner is not going to do what you think. $. & 2 is going to evaluate to true whenever the
adapting your one-liner to just print the lines gives
Did you actually test your adaptation of GrandFather's idea before posting? Changing between odd and even is as simple as if $. & 1 and unless $. & 1. Perhaps you could have a look at "Bitwise And" in perlop to further your understanding. Cheers, JohnGG Update: Corrected typo. Update 2: Corrected huge balls-up, thanks fenLisesi. Where did I get "2 is binary 100" from? Update 3: And thanks clinton, saw your reply after /msg from fenLisesi
In Section
Seekers of Perl Wisdom
|
|