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

[ID 20010308.003] Eval unable to access file-scoped lexical

March 8, 2001 14:26
[ID 20010308.003] Eval unable to access file-scoped lexical
Message ID:
This is a bug report for perl from,
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

The first is a simple script I call ex1, the second is a perl

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 and re-run the script and the expected output is 

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.


Lyle Brooks

# ----------------  Start of ex1 -----------------------


use strict;

require '';


# ----------------  Start of -----------------------


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;',

  @code = ();
  push @code, '$output = qq/', $stm, '/;';
  my $code = join("\n", @code);

print "Statement to Evaluate = :$code:\n";
  eval $code;
print "Evaluated Statement = :$output:\n";


[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:
    osname=linux, osvers=2.0.36, archname=i586-linux
    uname='linux 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
    cc='cc', optimize='-O2', gccversion=
    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:

Environment for perl 5.00502:
    LANG (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About