> But you said "lists" up there and that sparked an idea in me ... What
> does
>
> @a =~ /pattern/;
>
> currently do? AFAICT, nothing useful.
> Also, it'd be nice if
>
> @a =~ s/foo/bar/g;
>
> did something similar.
See RFC 170, "Generalize =~ to a special-purpose assignment operator".
It proposes that =~ be extended to an rvalue argument duplicator, so
these:
($name) = split /\s+/, $name;
$string = quotemeta($string);
@array = reverse @array;
@vals = sort { $a <=> $b } @vals;
$string = s/\s+/SPACE/, $string; # RFC 164
$matches = m/\w+/, $string; # RFC 164
@matches = m/\w+/, @strs; # RFC 164
@strs = s/foo/bar/gi, @strs; # RFC 164
Can be rewritten as the shorter and more readable:
($name) =~ split /\s+/;
$string =~ quotemeta;
@array =~ reverse;
@vals =~ sort { $a <=> $b };
$string =~ s/\s+/SPACE/; # looks familiar
$string =~ m/\w+/; # this too
@strs =~ m/\w+/; # cool extension
@strs =~ s/foo/bar/gi; # ditto
Some minimal discussions of the RFC can be found here:
http://www.mail-archive.com/perl6-language-regex@perl.org/msg00171.html
http://www.mail-archive.com/perl6-language-regex@perl.org/msg00182.html
But additional comments are always welcome, especially since little
discussion was recorded on it. I believe this should handle Tom's point
of:
fn() =~ s/pattern/newpattern/;
Since this would simply be equivalent to:
fn() = s/pattern/newpattern/, fn();
So context wouldn't change. There is a problem with this proposal and
how it interacts with plain old m//, so suggestions on fixing this are
welcome. I believe that returning the original string from the new
match() function suggested in RFC 164 is one way to solve this.
-Nate