This and other RFCs are available on the web at http://dev.perl.org/rfc/ =head1 TITLE Generalize =~ to a special-purpose assignment operator =head1 VERSION Maintainer: Nathan Wiger <[EMAIL PROTECTED]> Date: 29 Aug 2000 Mailing List: [EMAIL PROTECTED] Version: 1 Number: 170 Status: Developing Requires: RFC 164 =head1 ABSTRACT Currently, C<=~> is only available for use in specific builtin pattern matches. This is too bad, because it's really a neat operator. This RFC proposes a simple way to make it more general-purpose. =head1 DESCRIPTION First off, this assumes RFC 164. Second, it requires you drop any knowledge of how C<=~> currently works. Finally, it runs directly counter to RFC 139, which proposes another application for C<=~>. This RFC proposes a simple use for C<=~>: as a last-argument rvalue duplicator. What this means is that an expression such as this: $value = dostuff($arg1, $arg2, $value); Could now be rewritten as: $value =~ dostuff($arg1, $arg2); And C<$value> would be implicitly transferred over to the right side as the last argument. It's simple, but it makes what is being operated on very obvious. This enables us to rewrite the following constructs: ($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 @strs = s/foo/bar/gi, @strs; # RFC 164 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 [1] @strs =~ s/foo/bar/gi; # cool extension It's a simple solution, true, but it has a good amount of flexibility and brevity. It could also be the case that multiple values could be called and returned, so that: ($name, $email) = special_parsing($name, $email); Becomes: ($name, $email) =~ special_parsing; Again, it's simple, but seems to have useful applications. =head1 IMPLEMENTATION Simplistic (hopefully). =head1 MIGRATION This introduces new functionality, which allows backwards compatibility for regular expressions. As such, it should require no special translation of code. This RFC assumes RFC 164 will be adopted (which it may not be) for changes to regular expressions. True void contexts may also render some parts of this moot, in which case coming up with a more advanced use for C<=~> may be desirable. =head1 NOTES [1] That m// one doesn't quite work right, but that's a special case that I would suggest should be caught by some other part of the grammar to maintain backwards compatability (like bare //). =head1 REFERENCES RFC 164: Replace =~, !~, m//, and s/// with match() and subst() RFC 139: Allow Calling Any Function With A Syntax Like s///
