Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: experiencing slowness due to matching algorithm

by hippo (Bishop)
on Jan 09, 2023 at 09:53 UTC ( #11149447=note: print w/replies, xml ) Need Help??

in reply to experiencing slowness due to matching algorithm

I though regex here will be the fastest.

I have no idea why you thought that. Perhaps you could explain your reasoning?

An exact string match and an index match should beat 2 dynamic regexen into a cocked hat for speed.

if ($subpath eq $target || 0 == index $subpath, "$target/") {

Try profiling that and see if it improves matters for you.


Replies are listed 'Best First'.
Re^2: experiencing slowness due to matching algorithm
by ovedpo15 (Pilgrim) on Jan 09, 2023 at 10:36 UTC
    I will try it thanks!
    The problem is that 0 == index $subpath, "$target/" is not quite the same as $subpath =~ /^$target\// because I want it to start with $target. Is there something similar to startswith of Python?

      Please provide a value each for $subpath and $target where 0 == index $subpath, "$target/" is true and where $subpath does not start with $target.

      use strict; use warnings; use Test::More; my @tests = ( { subpath => 'foo/bar', target => 'bar' }, { subpath => 'foo/bar', target => 'ba' }, { subpath => 'foo/bar', target => 'oo' }, ); plan tests => scalar @tests; for my $t (@tests) { isnt index ($t->{subpath}, "$t->{target}/"), 0, "False, as expecte +d" }


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2023-03-22 10:38 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.