merlyn++. Neat! It's even a lot quicker than I thought it would be.
$text = do{ local $/; open W, '<dutch.words' or warn $!; <W> }; print length $text; 2603063 use Benchmark qw[ cmpthese ]; cmpthese( 1, { std=> q[ @words1 = $text =~ m[\b(\w+)\b]g; ], merlyn=> q[ @words2 = $text =~ m[ (?: (?<!\w)(?=\w) | (?<=\w)(?!\w) ) (\w+) (?: (?<!\w)(?=\w) | (?<=\w)(?!\w) ) ]xg ] }); (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) s/iter merlyn std merlyn 25.9 -- -50% std 13.0 98% -- print scalar @words1, ' : ', scalar @words2; 227248 : 227248
...proving your assertion wrong.
It could be argued that my assertion that "that \b is neither a lookahead nor a lookbehind assertion, try creating one of either" is correct... in that.
but that would probably be a fruitless argument, and takes nothing away from your construction. Once again, it's neat :)
In reply to Re: Re: Re: Why do zero width assertions care about lookahead/behind?
by BrowserUk
in thread Why do zero width assertions care about lookahead/behind?
by davido
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |