Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested eval scoping weirdness #1187

Closed
p5pRT opened this issue Feb 15, 2000 · 2 comments
Closed

nested eval scoping weirdness #1187

p5pRT opened this issue Feb 15, 2000 · 2 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 15, 2000

Migrated from rt.perl.org#2156 (status was 'resolved')

Searchable as RT2156$

@p5pRT
Copy link
Author

p5pRT commented Feb 15, 2000

From jcox@newton.interwoven.com

Created by jcox@interwoven.com

=head1 eval weirdness

  The following program outputs this​:

  foo : FOO
  bar : FOO <-------(case 1) hey!! wassup!
  bar : BAR <-------(case 2)
  foo : FOO

  Instead of this​:

  foo : FOO
  bar : BAR <-------(case 1) this is what I expected
  bar : BAR <-------(case 2)
  foo : FOO

  If eval creates a level of scope,
  and in the context of the bar() function, $x is BAR,
  it would seem that the behavior of nested eval is broken
  in case 1.
 
  The second eval in bar() (case 2) is my workaround.
 
  Am I missing something?

  Sincerely,

  -Jon Cox
  <jcox@​interwoven.com>

=cut

#------------------------------------------------------------------
#------------------------------------------------------------------

foo();

#------------------------------------------------------------------
#------------------------------------------------------------------

sub foo
{
  my $x = "FOO";
  my $y = ' print "foo : $x\n"; bar(); print "foo : $x\n"; ';
  eval $y;
}

#------------------------------------------------------------------
#------------------------------------------------------------------

sub bar
{
  my $x = "BAR";
  eval 'print "bar : $x\n"'; # case 1
  eval "my \$x = $x;\n" . 'print "bar : $x\n";'; # case 2
}

#------------------------------------------------------------------
#------------------------------------------------------------------

Perl Info


Site configuration information for perl 5.00502:

Configured by jcox at Mon Dec  7 18:01:13 PST 1998.

Summary of my perl5 (5.0 patchlevel 5 subversion 2) configuration:
  Platform:
    osname=solaris, osvers=2.6, archname=sun4-solaris
    uname='sunos newton 5.6 generic_105181-07 sun4u sparc sunw,ultrasparc-iii-engine '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='gcc', optimize='-O', gccversion=2.8.1
    cppflags='-I/usr/local/include'
    ccflags ='-I/usr/local/include'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lc -lcrypt
    libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='  -R /usr/local/lib/perl5/5.00502/sun4-solaris/CORE'
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches:
    


@INC for perl 5.00502:
    /usr/local/lib/perl5/5.00502/sun4-solaris
    /usr/local/lib/perl5/5.00502
    /usr/local/lib/perl5/site_perl/5.005/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.005
    .


Environment for perl 5.00502:
    HOME=/net/stargate/d2/iw/jcox
    LANG (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=.:/usr/local/microsoft/bin:/opt/SUNWspro/bin:/usr/ucb:/net/stargate/d2/iw/jcox/bin/sol:/net/stargate/d2/iw/jcox/bin:/sbin:/bin:/usr/bin:/usr/local/bin:/usr/sbin:/usr/ccs/bin:/usr/openwin/bin:/etc:/usr/etc:/usr/local/etc:/usr/local/jcoxstuff/iw-home/bin:~jcox/bin
    PERL_BADLANG (unset)
    SHELL=/net/stargate/d2/iw/jcox/bin/zsh


@p5pRT
Copy link
Author

p5pRT commented Feb 15, 2000

From @gsar

On Tue, 15 Feb 2000 21​:51​:29 PST, Jonathan Cox wrote​:

This is a bug report for perl from jcox@​interwoven.com,
generated with the help of perlbug 1.26 running under perl 5.00502.
[...]
=head1 eval weirdness

The following program outputs this​:

   foo : FOO
   bar : FOO       \<\-\-\-\-\-\-\-\(case 1\)  hey\!\! wassup\!
   bar : BAR       \<\-\-\-\-\-\-\-\(case 2\)
   foo : FOO

Instead of this​:

   foo : FOO
   bar : BAR       \<\-\-\-\-\-\-\-\(case 1\)  this is what I expected
   bar : BAR       \<\-\-\-\-\-\-\-\(case 2\)
   foo : FOO

Upgrade to 5.005_03.

Sarathy
gsar@​ActiveState.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant