Front page | perl.perl5.porters |
Postings from March 2001
[ID 20010308.003] Eval unable to access file-scoped lexical
From:
brooks
Date:
March 8, 2001 14:26
Subject:
[ID 20010308.003] Eval unable to access file-scoped lexical
Message ID:
200103082223.RAA16230@mosiah.deseret.com
This is a bug report for perl from perlmaster@deseret.com,
generated with the help of perlbug 1.26 running under perl 5.00502.
-----------------------------------------------------------------
[Please enter your report here]
I believe that there is a problem with eval not being able to
"see" a file scoped lexical.
I have included the two files that are needed to reproduce the
problem.
The first is a simple script I call ex1, the second is a perl
module Foo.pm
The expected output should contain the text
"This is a BIG,FAT deal!"
Instead you get
"This is a BIG, deal!"
The string "FAT" is held in a file-scoped lexical $fat.
I think $fat should be accessible to the eval statement
that is at the bottom of Foo::built_it()
However, if you refer to $fat somewhere in Foo::built_it(),
then eval can "see" $fat. Uncomment the line indicated in
Foo.pm and re-run the script and the expected output is
produced.
Of course, this may be a gap in my understanding of Perl, but
I wouldn't be sending this bug report if I thought that were
the case.
Let me know if this is truly a bug or what I am missing if
it is not.
Thanks.
Lyle Brooks
brooks@deseret.com
# ---------------- Start of ex1 -----------------------
#!/usr/bin/perl
use strict;
require 'Foo.pm';
&Foo::build_it;
# ---------------- Start of Foo.pm -----------------------
#!/usr/bin/perl
use strict;
package Foo;
my $fat = 'FAT';
my $stm = q/This is a @{ [ join(",", $big, $fat) ]} deal!/;
sub build_it {
my $big = 'BIG';
my $output;
#$fat; # Uncomment this and you get FAT
my @code;
push @code, '$output =<<END;',
$stm,
'END';
@code = ();
push @code, '$output = qq/', $stm, '/;';
my $code = join("\n", @code);
print "Statement to Evaluate = :$code:\n";
eval $code;
print "Evaluated Statement = :$output:\n";
}
1;
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Site configuration information for perl 5.00502:
Configured by brooks at Wed Nov 17 13:15:41 EST 1999.
Summary of my perl5 (5.0 patchlevel 5 subversion 2) configuration:
Platform:
osname=linux, osvers=2.0.36, archname=i586-linux
uname='linux mosiah.deseret.com 2.0.36 #1 tue oct 13 22:17:11 edt 1998 i586 unknown '
hint=previous, useposix=true, d_sigaction=define
usethreads=undef useperlio=undef d_sfio=undef
Compiler:
cc='cc', optimize='-O2', gccversion=2.7.2.3
cppflags='-Dbool=char -DHAS_BOOL'
ccflags ='-Dbool=char -DHAS_BOOL'
stdchar='char', d_stdstdio=define, usevfork=false
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
libc=, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Locally applied patches:
---
@INC for perl 5.00502:
/usr/lib/perl5/5.00502/i586-linux
/usr/lib/perl5/5.00502
/usr/lib/perl5/site_perl/5.005/i586-linux
/usr/lib/perl5/site_perl/5.005
.
---
Environment for perl 5.00502:
HOME=/home/brooks
LANG (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/brooks/bin:/usr/bin:/opt/oracle/bin:/home/brooks/bin:/usr/local/bin:/home/data_sync/bin:/usr/X11R6:/usr/X11R6/bin:/usr/bin/X11:/usr/sbin:/sbin:/usr/bin:/bin:.
PERL_BADLANG (unset)
SHELL=/bin/tcsh
-
[ID 20010308.003] Eval unable to access file-scoped lexical
by brooks