develooper Front page | perl.perl5.porters | Postings from March 2000

do() sees lexicals if called from sub

From:
Peter Scott
Date:
March 6, 2000 13:52
Subject:
do() sees lexicals if called from sub
Message ID:
4.2.2.20000306133127.00adca80@mail.psdt.com
Something I posted on clpmod recently was further refined by David Dyck and 
appears to be a bug.  Observed in 5.005_03 on Solaris and 5.5.650 on Linux; 
also observed by Malcolm Dew-Jones on 5.005_03 on Win32.

Quoth perlfunc:

	code evaluated with do FILENAME cannot see lexicals
	in the enclosing scope;

It appears that it *can* see lexicals in the enclosing scope if it is 
called via a subroutine.  (I discovered this when I typed in the 
pseudo-definition of require as a sub from perlfunc.)

% cat foo
my $x = "main";
do 'bar';
print "\$x set in $x\n";
blech();
print "\$x set in $x\n";

sub blech {
   $x = "blech";
   do 'bar';
}

% cat bar
$x = "bar";
print "In bar\n";

% perl -w -Mstrict foo
In bar
$x set in main
In bar
$x set in bar


--
Peter Scott
Pacific Systems Design Technologies




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About