Affixing bug id. Patch at end. -------- Original Message -------- Subject: Re: do() sees lexicals if called from sub Date: Mon, 6 Mar 2000 17:08:22 -0500 References: <4.2.2.20000306133127.00adca80@mail.psdt.com> On Mon, Mar 06, 2000 at 01:51:17PM -0800, Peter Scott wrote: > 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 > It appears that the first do creates a package variable named $x, and that after the second do the package variable has taken over the lexical variable. Stepping through the debugger, x $x and X x return different values up until the second do 'bar';. Ronald --end of forwarded text-- This appears to fix it. There may be a couple of other places that could benefit by referencing OP_DOFILE but I didn't look too closely and I'm going on vacation tomorrow. Rick *** perl-5.5.670/pp_ctl.c.old Wed Mar 8 10:43:58 2000 --- perl-5.5.670/pp_ctl.c Wed Mar 8 11:06:59 2000 *************** *** 2728,2734 **** av_store(comppadlist, 1, (SV*)PL_comppad); CvPADLIST(PL_compcv) = comppadlist; ! if (!saveop || saveop->op_type != OP_REQUIRE) CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(caller); SAVEFREESV(PL_compcv); --- 2728,2735 ---- av_store(comppadlist, 1, (SV*)PL_comppad); CvPADLIST(PL_compcv) = comppadlist; ! if (!saveop || ! (saveop->op_type != OP_REQUIRE && saveop->op_type != OP_DOFILE) ) CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(caller); SAVEFREESV(PL_compcv);Thread Next