![]() |
|
The stupid question is the question not asked | |
PerlMonks |
Is there a way to allow consecutive zero-length matches without using pos()?by jsm (Novice) |
on Nov 03, 2017 at 00:40 UTC ( [id://1202659]=perlquestion: print w/replies, xml ) | Need Help?? |
jsm has asked for the wisdom of the Perl Monks concerning the following question: I have a specialized parser of JavaScript (written in Perl) that often legitimately matches consecutive zero-length strings. As described here, Perl intentionally disallows this, to fix a class of potential infinite-loop bugs. The normal solution is to set pos() on the input string to reset its zero-length flag. However, in Perls from 5.18 to 5.24, this is very slow when looping through large strings, performing as O(n^2). It may be this bug (my program is a CGI script, thus related to tainting). It's fixed in Perl 5.26, but my program is used in many contexts where the users are not able to upgrade their version of Perl. My question is: Is there a way other than setting pos() to allow a string to have consecutive zero-length matches? I've tried pos($$in)= pos($$in) and pos($$in)+= 0, but either statement ends up doubling the run time of the whole script. The script is already CPU-intensive, so performance is important here. (I picture a potential /z regex modifier that allows consecutive zero-length matches.) Thanks a lot for any suggestions! UPDATE: It appears to have nothing to do with tainting, but with the UTF-8 flag on the string. Here's a code sample that demonstrates the problem:
Back to
Seekers of Perl Wisdom
|
|