in reply to Re (tilly) 3: Finally, a $& compromise!
in thread Finally, a $& compromise!

"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")

Replies are listed 'Best First'.
Re (tilly) 5: Finally, a $& compromise!
by tilly (Archbishop) on Nov 28, 2001 at 21:55 UTC
    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:??;