Rob Mueller (fastmail) wrote: > I recently had a similar problem. A regex that worked fine in sample code > was a dog in the web-server code. It only happened with really long strings. > I tracked down the problem to this from the 'perlre' manpage. > > WARNING: Once Perl sees that you need one of "$&", "$`", or "$'" > anywhere in the program, it > has to provide them for every pattern match. This may substantially > slow your program. Perl > uses the same mechanism to produce $1, $2, etc, so you also pay a > price for each pattern that > contains capturing parentheses. (To avoid this cost while retaining > the grouping behaviour, > use the extended regular expression "(?: ... )" instead.) But if you > never use "$&", "$`" or > "$'", then patterns without capturing parentheses will not be > penalized. So avoid "$&", > "$'", and "$`" if you can, but if you can't (and some algorithms > really appreciate them), > once you've used them once, use them at will, because you've already > paid the price. As of > 5.005, "$&" is not so costly as the other two. > > Basically one of the modules in the web-app I was 'use'ing needed $', but my > test code didn't 'use' that module. The result was pretty dramatic in this > case, something that took approx 1 second in the test code was timing out > after 2 minutes in the web-server. > > What I did in the end was something like this: > > In the code somewhere add this so it's run when a request hits. > > open(F, '>/tmp/modulelist'); > print F join("\n", values %INC), "\n"; > close(F); > > This creates a file which lists all the loaded modules. Then after sticking > a request through the browser, do something like: > > grep \$\' `cat /tmp/modulelist` > grep \$\& `cat /tmp/modulelist` > grep \$\` `cat /tmp/modulelist` > > to try and track down the offending module. You'll get quite a few false > hits (comments, etc), but you might find an offending module. The main ones
Also check Devel::FindAmpersand and Devel::SawAmpersand. cpan> i /ampersand/ Distribution A/AN/ANDK/Devel-SawAmpersand-0.20.tar.gz Module Apache::SawAmpersand (Contact Author The Perl/Apache Mailing List <[EMAIL PROTECTED]>) Module B::FindAmpersand (A/AN/ANDK/Devel-SawAmpersand-0.20.tar.gz) Module Devel::FindAmpersand (A/AN/ANDK/Devel-SawAmpersand-0.20.tar.gz) Module Devel::SawAmpersand (A/AN/ANDK/Devel-SawAmpersand-0.20.tar.gz) 5 items found The Devel::SawAmpersand also explains a workaround for using &. _____________________________________________________________________ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://ticketmaster.com http://apacheweek.com http://singlesheaven.com http://perl.apache.org http://perlmonth.com/