in reply to Empty pattern in regex
Why is "f" printed?
I would have expected the question 'why are "f" and "g" printed'. Do you agree that printing "g" is also surprising, for the same reason? (If not, I may be misunderstanding random parts of your post.)
Why is there the empty regex (see (*))?
I don't know, seems very odd to me. I suggest reporting it as a possible bug.
It seems possible that since the last successfully matched regexp was /d/, and the last attempted match against that regexp was a fail, it may have somehow marked it as no longer successfully matched; but that doesn't explain the change of behaviour when you add the empty continue block.
I suspect rather that it is a scoping bug: I'm not sure if the docs make this clear, but it is intended to use the last successfully matched regexp visible to the current scope. Thus:
% perl -wle '"a" =~ /a/; { "b" =~ /b/ } "ab" =~ // and print $&' a %
FWIW p5p mostly regards the empty regexp behaviour as a misfeature reluctantly spared the axe only because of the constraints of backward compatibility - it is very rare to see anyone actually trying to make use of it. But since we have it, it certainly ought to work as advertised.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Empty pattern in regex
by perlboy_emeritus (Scribe) on Oct 19, 2023 at 18:45 UTC | |
by choroba (Cardinal) on Oct 19, 2023 at 19:02 UTC | |
by perlboy_emeritus (Scribe) on Oct 20, 2023 at 20:08 UTC | |
by hv (Prior) on Oct 19, 2023 at 19:56 UTC | |
by perlboy_emeritus (Scribe) on Oct 19, 2023 at 20:44 UTC |