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 Version: 1 Mailing List: [EMAIL PROTECTED] Number: 158 =head1 ABSTRACT This RFC addresses ways to make the regex special variables $`, $& and $' not be such pariahs like they are now. =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 There are two part I have for the implementation and they work together. First, $`, $& and $' will be scoped just like $1 and friends. They will be set by the regex and be only accessible in the current block or a block which starts with a regex like: if ( /foo/ ) { But the problem of knowing whether those vars are used by a given regex remains. This 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
