Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: experiencing slowness due to matching algorithm

by NERDVANA (Deacon)
on Jan 09, 2023 at 15:57 UTC ( [id://11149460]=note: print w/replies, xml ) Need Help??


in reply to experiencing slowness due to matching algorithm

To add a little more context than Hippo's answer: Because you have a variable substitution on the pattern, perl can't pre-compile the regex and so each time it hits that line it performs two regex compiles and two regex comparisons. While in this case "index" will be the ideal approach, if you ever have a similar case where you do need a regex, I recommend this:
if ($subpath =~ m:^\Q$target\E(/|$):) {

The \Q and \E perform escaping of the $target so that regex special characters in $target don't get interpreted as regex structure, I used m:...: instead of /.../ because you have a literal / in the pattern and this way you don't need to escape it, and the alternation ending of / or $ lets you match with a single regex.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-04-18 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found