Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^6: Why is "any" slow in this case?

by LanX (Saint)
on Jul 30, 2025 at 22:18 UTC ( [id://11165882]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Why is "any" slow in this case?
in thread Why is "any" slow in this case?

> please test thoroughly, I just hacked the code into my mobile as an example ...

as expected the first approach was buggy.

This approach seems to pass the tests (using 1 for 0 to test more edge cases)

Hint: Anchoring is tricky when dealing with variable length strings and look-aheads.

use v5.14; use warnings; say "INPUT: ",my $str = join " ", 0 ..34; my %DONT; @DONT{1, 15, 16, 31}=(); my $stop=15; my $donts = join "|", keys %DONT; say my $dont_re = "(?!(?:$donts)\\b)"; while ( $str =~ m/\b$dont_re(\d+) \b$dont_re(\d+)/g ) { say "$1 $2"; die unless $stop--; exists $DONT{$_} and die "$_ forbidden" for $1,$2; }

INPUT: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2 +4 25 26 27 28 29 30 31 32 33 34 (?!(?:31|1|15|16)\b) 2 3 # <-- no 0,1 4 5 6 7 8 9 10 11 12 13 # <-- no 14,15,16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 # <-- no 31 32 33 # <-- no 34

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

UPDATE

had to improve the rexex again... :/

Probably a negative-look-behind is easier and faster.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2026-03-08 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.