This and other RFCs are available on the web at http://dev.perl.org/rfc/ =head1 TITLE Regular Expression Special Variables =head1 VERSION Maintainer: Uri Guttman <[EMAIL PROTECTED]> Date: 25 Aug 2000 Last Modified: 22 Sep 2000 Mailing List: [EMAIL PROTECTED] Number: 158 Version: 2 Status: Frozen =head1 ABSTRACT This RFC addresses ways to make the regex special variables $`, $& and $' not be such pariahs like they are now. =head1 CHANGES I dropped the local scoping of $`, $& and $' as per the request of MJD. I disagree but he is/was chair of the regex list. =head1 DESCRIPTION $`, $& and $' are useful variables which are never used by any experienced Perl hacker since they have well known problems with efficiency. Since they are globals, any use of them anywhere in your code forces all regexes to copy their data for potential later referencing by one of them. I will describe some ideas to make this issue go away and return these variables back into the toolbox where they belong. =head1 IMPLEMENTATION The always copy all regex data problem is solved by a new modifier k (for keep). This tells the regex to do the copy so the 3 vars will work properly. So you would use code like this: $str = 'prefoopost' ; if ( $str =~ /foo/k ) { print "pre is [$`]\n" ; print "match is [$&]\n" ; print "post is [$']\n" ; } print "$` is undefined here.\n" ; =head1 IMPACT None =head1 UNKNOWNS None =head1 REFERENCES None