What I really want is conditional support for $` and $'. That is much worse.
To give a simple example, try the following 3 programs:
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.#!/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";
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |