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

Re: Re^2: Can this be a 1 line or simpler regex?

by diotalevi (Canon)
on Apr 06, 2003 at 02:40 UTC ( [id://248378]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Can this be a 1 line or simpler regex? (slightly better?)
in thread Can this be a 1 line or simpler regex?

Ew. That that sprinkles eval blocks all over. That's also suboptimal. The original poster had the best version already. I fixed my own code to be nearly similar except that it doesn't benefit from perl's ability to compile a static regex only once. Your code is a static regex but you're imposing eval {} at each match point.

An entirely different route might be to do some code generation so that the common parts are written only once, eval blocks aren't sprinked all over the place and the world is good again. The only issue is that now its not pretty anymore.

# Keep $escape somewhere or give it a proper name. my $escape = eval "sub {\n".join("\n",map " \$_[0] =~ s/\\$_/\\\\$_ +/g;", qw/t r n f/)."\n};"; $escape->( $text );

Replies are listed 'Best First'.
Re^4: Can this be a 1 line or simpler regex? (s///e does not eval)
by Aristotle (Chancellor) on Apr 06, 2003 at 11:49 UTC
    you're imposing eval {} at each match point
    Sorry, no. You're confusing /e with /ee. There's no evaling with /e.

    Makeshifts last the longest.

      Huh. I wouldn't have guessed. The first /e isn't an eval, any other /e's are eval string blocks with all of the $@ overwriting semantics.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found