Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: speeding up a regex

by Perl Mouse (Chaplain)
on Jan 03, 2006 at 16:04 UTC ( #520650=note: print w/replies, xml ) Need Help??


in reply to Re^3: speeding up a regex
in thread speeding up a regex

modern perls have optimisations to avoid recompiling patterns if the interpolated variables havenít changed
Modern perls are even smarter than that. They look at the string after interpolation, and if that's the same, the regex isn't executed:
$ cat xx #!/usr/bin/perl use strict; use warnings; foreach my $x (["foo", "bar"], ["fo", "obar"]) { my ($foo, $bar) = @$x; "" =~ /$foo/; "" =~ /$foo$bar/; } __END__ $ perl -Dr xx 2>&1 | perl -nle 'if (/EXECUTING/ .. eof) {print if/^Compiling/}' Compiling REx `foo' Compiling REx `foobar' Compiling REx `fo'
Perl won't recompile the second regex, since while the values of both $foo and $bar have changed, the value of "$foo$bar" hasn't.
Perl --((8:>*

Log In?
Username:
Password:

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

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












    Results (238 votes). Check out past polls.

    Notices?