Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- replace words
September 7, 2009, 11:51 pm
rate this thread
This command is working. I can change && for foo1 and foo2.
perl -0 -pe 's(&&)(++$n < 2 ? "&foo1&" : "&foo2&")eg' text.txt
Please explain to me why the command is not working for foo3.
perl -0 -pe 's(&&)(++$n < 2 ? "&foo1&" : "&foo2&" : "&foo3&" )eg'
Re: replace words
The "condition ? value1 : value2" is an if/else condition. If the
condition is true, it'll place value1 "or else" value2 if it's not met.
If you want it to run another test before knowing if foo2 or foo3 is
going to be placed, you need to add another conditional. Of course,
it's not clear what you want to do in your example above. What do you
want it to accomplish?