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

do() sees lexicals if called from sub

Thread Previous | Thread Next
Peter Scott
March 6, 2000 13:52
do() sees lexicals if called from sub
Message ID:
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";
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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About