Perl: Why doesn't eval '/(...)/' set $1?
If a regular expression match occurs inside an eval, changes to the capture-related variables ($1, etc.) are not visible in the outside environment.  Is this a bug?

*perlop* and *perlre* don't seem to mention any such restriction.

For example:

     use strict; use warnings;
     $_ = "hello";
     eval '/(.*)/';
     print "GOT: $1\n";
gives:
     

    Use of uninitialized value $1 in concatenation (.) or string at -e line 1.
    GOT:

A more succinct demo is:

    perl -we '$_="foo"; eval q(/(.*)/;) ; print "GOT:$1\n";'
Perl: Why doesn't eval '/(...)/' set $1?
===

If a regular expression match occurs inside an eval, changes to the capture-related variables ($1, etc.) are not visible in the outside environment.  Is this a bug?

*perlop* and *perlre* don't seem to mention any such restriction.

For example:

     use strict; use warnings;
     $_ = "hello";
     eval '/(.*)/';
     print "GOT: $1\n";
gives:
     

    Use of uninitialized value $1 in concatenation (.) or string at -e line 1.
    GOT:

A more succinct demo is:

    perl -we '$_="foo"; eval q(/(.*)/;) ; print "GOT:$1\n";'