Nice, but after some playing around I can guarantee that you have solved the least of my problems.

What I really want is conditional support for $` and $'. That is much worse.

To give a simple example, try the following 3 programs:

#!/usr/bin/perl # This demonstrates matching through a string use strict; use Time::HiRes qw(gettimeofday); my $start = gettimeofday(); my $str = "_" x $ARGV[0]; 1 while $str =~ /./g; my $elapsed = gettimeofday() - $start; print "$ARGV[0] characters took $elapsed seconds\n"; #!/usr/bin/perl # This demonstrates matching through a string, capturing use strict; use Time::HiRes qw(gettimeofday); my $start = gettimeofday(); my $str = "_" x $ARGV[0]; 1 while $str =~ /(.)/g; my $elapsed = gettimeofday() - $start; print "$ARGV[0] characters took $elapsed seconds\n"; #!/usr/bin/perl # This demonstrates matching through a string, capturing $` use strict; use Time::HiRes qw(gettimeofday); # Mess life up here if ("gotcha" =~ /o/) { my $fooey = $`; } my $start = gettimeofday(); my $str = "_" x $ARGV[0]; 1 while $str =~ /(.)/g; my $elapsed = gettimeofday() - $start; print "$ARGV[0] characters took $elapsed seconds\n";
If you try it you will find that the first two versions run linearly, with only a modest speed difference for the capturing. But the third is a quadratic speed drop. Should you ever, as I do, use REs as a way of tokenizing, this means that the use of a single $` or $', anywhere, turns linear algorithms quadratic. By contrast turning $& on and off is not going to change your program's scalability.

For that reason if I write something for other people's use, I would really like the option of turning off $` and $' lexically. Because I want access to $1 without being hammered with $` and $'.


In reply to Re (tilly) 1: Finally, a $& compromise! by tilly
in thread Finally, a $& compromise! by japhy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.