The stupid question is the question not asked | |
PerlMonks |
(Ab)using the Regex Engineby jo37 (Deacon) |
on May 25, 2020 at 09:19 UTC ( [id://11117224]=perlmeditation: print w/replies, xml ) | Need Help?? |
The TASK #2 of perl-weekly-challenge-061 was to split a given string into certain subparts. There were two solutions that (ab)use Perl's regular expression engine to get all matches for the leading part of a regular expression. Though being one of the authors, I'm not so sure about this approach. How smart is the engine allowed to be? Is there a way to guarantee that it actually tries all possibilities? The section Embedded Code Execution Frequency in perlre says: How non-accepting pathways and match failures affect the number of times a pattern is executed is specifically unspecified and may vary depending on what optimizations can be applied to the pattern and is likely to change from version to version.This is a rather clear statement, that the proposed solutions may fail in future versions of Perl. But does this hold in any case? See examples in this program:
Explanations to the numbered samples:
A (??{CODE}) block is guaranteed to be executed, if the failing or success of a pathway containing this block solely depends on the returned subexpression.Could we even have a zero-width assertion like (?!?{CODE}) that always fails but must not be optimized away in the sense of the previous proposition? I'd be glad to see your opinions. BTW: What matches and what is matched? Is a regex matching a string or is a string matching a regex? I don't know. Greetings,
Back to
Meditations
|
|