Closed p5pRT closed 20 years ago
=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 }
#------------------------------------------------------------------ #------------------------------------------------------------------
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
Migrated from rt.perl.org#2156 (status was 'resolved')
Searchable as RT2156$