in reply to Re: Another regex variable puzzle
in thread Another regex variable puzzle

You're not going crazy.
Thank you japhy, that's reassuring :-)

The scope of $<digit> (and $`, $&, and $') extends to the end of the enclosing BLOCK or eval string, or to the next successful pattern match, whichever comes first.

But it does not say that those vars will not be mangled by a passing-by unsuccessful match :-(

What you discovered/confirmed (Perl LINKS the digit variables to SECTIONS of the string) should be documented in bold letters right in the perlre page where a perl newbie first meets those variables.Did you submit that bug report?

It would be good if the behavior of $<digit> variables could be specified and implemented such that at any time they either contain the result of the last successful match or are undefined. In the meantime, I will remember not to rely on them and use the list assignment.

Rudif

Replies are listed 'Best First'.
Re: Re: Re: Another regex variable puzzle
by japhy (Canon) on Mar 04, 2001 at 03:46 UTC
    I reported and fixed the bug. All it took was removing a statement in pp_hot.c that said, in English, "if the pattern match is happening in list context, don't make copies of $1, $2, etc."

    So in the next version of Perl, your bug will be no more. It was a peculiar bug... behavior-wise, at least. I guess they thought that if you're storing the digit variables in other variables, there's no need to make copies of them, but rather, link those digit variables to parts of the string directly.

    japhy -- Perl and Regex Hacker

      All it took was removing a statement in pp_hot.c

      Thank you for a hot fix :-)

      Rudif