What I had in mind with my comment about the m//o modifier is that b4swine might be receiving a complex regex and then interpolating it a la m/...$re.../ during actual matching (as, indeed, you show in your example). This might be done if some additional match condition(s) were to be imposed on every received regex, e.g., adding a \z anchor at the end to force end-of-string matching. Of course, I don't know that anything like this is actually happening; it was just a thought.
For regexes interpolated into m// matches, use of the /o modifier seems beneficial in some cases, apparently depending on Perl version. (I know that work is being done continuously to refine and optimize regex matching.) For instance, under two older Perl versions that I have access to ATM (ActiveState 5.8.9 and Strawberry 5.14.4.1), benchmarking shows a significant benefit in the newer Perl for using /o when interpolating into an m// match (assuming this is a valid benchmark, and benchmarks can be tricky :).
use strict;
use warnings;
use Benchmark qw(cmpthese);
print "perl version $] \n";
my $rx = qr{X}xms;
cmpthese(-1, {
'qr_bound' => sub { 'Y' =~ $rx ; },
'qr_interp' => sub { 'Y' =~ / $rx / ; },
'qr_interp_o' => sub { 'Y' =~ / $rx /o; },
'm_empty' => sub { 'Y' =~ //; },
'm_empty_o' => sub { 'Y' =~ //o; },
});
Output:
c:\@Work\Perl\monks\belg4mit>perl cmp_qr_compilation_1.pl
perl version 5.008009
Rate qr_interp qr_interp_o qr_bound m_empty
+ m_empty_o
qr_interp 2880477/s -- -9% -43% -55%
+ -67%
qr_interp_o 3181791/s 10% -- -37% -51%
+ -64%
qr_bound 5078627/s 76% 60% -- -21%
+ -42%
m_empty 6452035/s 124% 103% 27% --
+ -26%
m_empty_o 8775008/s 205% 176% 73% 36%
+ --
c:\@Work\Perl\monks\belg4mit>perl cmp_qr_compilation_1.pl
perl version 5.014004
Rate qr_bound qr_interp m_empty m_empty_o q
+r_interp_o
qr_bound 1004609/s -- -70% -76% -80%
+ -92%
qr_interp 3378700/s 236% -- -20% -33%
+ -74%
m_empty 4237856/s 322% 25% -- -16%
+ -68%
m_empty_o 5068698/s 405% 50% 20% --
+ -61%
qr_interp_o 13135439/s 1208% 289% 210% 159%
+ --
The
qr// comparisons are between failing matches because that's what I imagine would happen most often in the actual application. I just threw in some successful
// null matches out of curiosity.
Give a man a fish: <%-{-{-{-<
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.