Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Escape Quote-Like Operators

by kennethk (Monsignor)
on Sep 11, 2013 at 18:37 UTC ( #1053547=note: print w/ replies, xml ) Need Help??


in reply to Escape Quote-Like Operators

What's your actual use case? You can save a bunch of characters by not branching (in your nonsensical example):

$_ = '12'; s/\d/n/g;s/n+/m/;
Update: Or, if you pay 3 more (still saving 2 from your 'ideal') you can get identical algorithmic behavior:
$_ = '12'; s/\d\d+/m/||s/\d/n/;
LTS FTW

Thanks to Anonymous Monk, realized my brain misread the comparator. However, the real use case is still relevant. As penance, optimization of the nonsensical example:

$_ = '12'; s/\d+/$&>10?'m':n/e;

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: Escape Quote-Like Operators
Select or Download Code
Re^2: Escape Quote-Like Operators
by Anonymous Monk on Sep 11, 2013 at 20:24 UTC

    Wouldn't that replace '10' with 'm' by mistake?

      It would; parse fail.


      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-10-22 00:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (112 votes), past polls