perlquestion
Ovid
<p>I'm researching some performance problems with one of our Web sites and stumbled across some legacy code that's getting pulled into our system. This code uses <tt>$`</tt> and <tt>$'</tt> variables with regular expression matches. From the [perlre] docs (emphasis mine):</p>
<blockquote>WARNING: Once Perl sees that you need one of "$&", "$`", or "$'" <em>anywhere in the program</em>, it has to provide them for every pattern match. This may substantially slow your program.</blockquote>
<p>In fact, in tests that I've run, it appears that the mere existence of these variables will trigger this behavior, regardless of whether or not the code that accesses them will be executed. Removing these variables seems to consistently get me a ten percent bump in regex performance.</p>
<p>Since mod_perl is a persistent Perl interpreter embedded in the Web server, it seems to me that any reference to these variables will impact all regex matches in a mod_perl environment, regardless of whether or not my code actually uses those variables. Is this the case? I don't know enough about benchmarking snippets in a mod_perl environment to easily verify this.</p>
<div class="pmsig"><div class="pmsig-17000">
<p>Cheers,<br />
<a href="/index.pl?node=Ovid&lastnode_id=1072">Ovid</a></p>
<p><small>New address of <a href="http://users.easystreet.com/ovid/cgi_course/">my CGI Course</a>.</small></p>
</div></div>