Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Escape Quote-Like Operators

by kennethk (Abbot)
on Sep 11, 2013 at 18:37 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1053547]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-23 07:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found