Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: conditional statement in substitution expression

by Roy Johnson (Monsignor)
on Aug 04, 2009 at 17:16 UTC ( #785837=note: print w/ replies, xml ) Need Help??


in reply to conditional statement in substitution expression

s/\*\*([^\*]+)\*\*\s\,\s\*\*([^\*]+)\*\*(\s\,)?/(grep {index($_,'_') +>=0} $1,$2)?"**$1_($2)**":$&/ge;
This incurs the performance penalty for using $&, so you might prefer
while(<DATA>) { s/(\*\*([^\*]+)\*\*\s\,\s\*\*([^\*]+)\*\*(\s\,)?)/(grep {index($_,'_ +')>=0} $2,$3)?"**$2_($3)**":$1/ge; print; }

Caution: Contents may have been coded under pressure.


Comment on Re: conditional statement in substitution expression
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://785837]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2015-07-03 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (50 votes), past polls