in reply to (tye)Re2: Finally, a $& compromise!
in thread Finally, a $& compromise!

As specifically pointed out in the section Capturing still works, the use of $1 and friends turns support for them back on, despite the pragma.

I did read what japhy wrote before I posted. While it is nice to turn off the production of capturing strings, the main time I do enough matching that I really care about capturing or not is tokenizing, when I am almost definitely going to be using capturing matches. So this module helps with the problem, but not in the only case where I care.

  • Comment on Re (tilly) 3: Finally, a $& compromise!

Replies are listed 'Best First'.
(tye)Re3: Finally, a $& compromise!
by tye (Sage) on Nov 28, 2001 at 21:39 UTC

    "sawampersand" is a single bool. I can't come up with any reason that this code would need to have "sawampersand" be treated as "true" when capturing is being done. I think either japhy was not being completely clear when he wrote that paragraph or he misunderstood some subtleties about how $& and capturing interact.

    Sorry you felt that I was accusing you of not reading.

            - tye (but my friends call me "Tye")
      japhy explains the connection better in Re: Re: Finally, a $& compromise!.

      If I understand what he is doing correctly, he is only playing games with deciding whether or not to capture. If you capture, the decision of whether or not to capture $` and $' is separate.

      I would like the pragma to be able to decide not just whether or not to capture, but whether or not to copy the whole string. $`/$' are already distinguished from $& in Perl, and separate control would be nice here.

      UPDATE
      As just discussed in chatter. Using $& is documented in perlre (as of 5.005 and later) as not being as bad as $` and $'. But in my simple test above, it produced the same slowdown. Which indicates a mistake in the documentation...

        Ok. I think there is a bug with the current Perl right now:
        #!/usr/bin/perl -l $_ = "japhy"; 1 while /(.)/g; $_ = "upset"; print $1; # does this print 'y' or 't' for you?
        That code prints "t" for my bleadperl. This means that Perl is not copying the string it matches, but just using a pointer to the string. That explains why this code runs JUST AS FAST as
        #!/usr/bin/perl -l $_ = "japhy"; 1 while /./g; $_ = "upset";
        Now, this makes the test tilly wrote null and void.

        _____________________________________________________
        Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
        s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;