Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: match function

by Marshall (Canon)
on Jun 10, 2020 at 20:13 UTC ( [id://11117918]=note: print w/replies, xml ) Need Help??


in reply to match function

I liked all of the comments in this thread. I would add a cautionary note about the use of $'.
In Perl versions <5.20 just this statement my $afterstring  = $'; can cause a huge regex performance penalty on every regex in the entire script, not just limited to where this variable is actually used. https://perldoc.perl.org/perlvar.html gives the gory details. This thread shows a number of ways to avoid using this special variable and I recommend doing so. Perl versions can remain in use for a surprisingly long time because Perl is integral to the operation of many OS's and there will be a default "system Perl" that is only updated in a very conservative way. There are plenty of Perl 5.8 installations still out there. I don't see any compelling reason to use $' in this example and would not do so.

Replies are listed 'Best First'.
Re^2: match function
by AnomalousMonk (Archbishop) on Jun 10, 2020 at 22:20 UTC

    The "Performance issues" sub-section of perlvar that Marshall links to covers this of course, but I think it's worth emphasizing that the related variables  $` $& $' all have the same problem prior to Perl 5.20.


    Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-23 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found