in reply to Re^5: Why is "any" slow in this case?
in thread Why is "any" slow in this case?
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
had to improve the rexex again... :/
Probably a negative-look-behind is easier and faster.
|
---|