Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: $1[

by kennethk (Abbot)
on Oct 10, 2017 at 20:33 UTC ( #1201119=note: print w/replies, xml ) Need Help??


in reply to $1[

This falls into the general class of "I'm using a regex, but my expression is starting to look like noise." The fastest solution in this case is use the x modifier since you don't have any whitespace in your expression:
s/ \) ([^()]+) \( / ] $1 [ /xg;
That's your original expression with extra whitespace.

I personally don't see the value in reducing your character count by 2 by avoiding the backslashes in the first place, but this type of process is always susceptible to Leaning_toothpick_syndrome. If I'm doing something like this, with potential nesting and the like, I always build a tree using tokens. My experience has generally shown that in these scenarios the fast solution is never actually fast.


#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://1201119]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2020-10-27 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (256 votes). Check out past polls.

    Notices?