Mailing List Archive

perl5 - Bug or Feature
Hey!

I discovered a bizarre behaviour of a perl script. Many people encouraged me to
ask for your opinion about this behaviour: It's a bug or a feature?

The script I am talking about is the following:

#!/usr/local/bin/perl

&bug_sub();

sub bug_sub {
my($i); # This my() makes no sense, but I need it
# to show the bizarre behaviour

for $i (0 .. 3) {
print($i, " ");
eval('0 < $i'); # This eval() does not change $i. Shure.
# This eval() makes no sense, of course!
print($i, " ");
eval('0 < $i*2.4'); # This eval() changes $i. Why?
print($i, "\n");
}
}

Running this script, I expect the following output:
0 0 0
1 1 1
2 2 2
3 3 3

Nevertheless, I recive the following output (On HP9000/S700 and on
IBM/RS6000, using "perl, version 5.001 Unofficial patchlevel 1m"):
0 0 0
1 1 2.4
2 2 4.8
3 3 7.2

Please have a look at it.

Thanks
Georg
Re: perl5 - Bug or Feature [ In reply to ]
In <9512042048.AA22515@rpool3.rus.uni-stuttgart.de>
On Mon, 4 Dec 1995 21:48:41 +0100 (MEZ)
Georg Voorwinden <georg.voorwinden@studbox.uni-stuttgart.de> writes:
>Hey!
>
>I discovered a bizarre behaviour of a perl script. Many people encouraged me to
>ask for your opinion about this behaviour: It's a bug or a feature?
>
>Nevertheless, I recive the following output (On HP9000/S700 and on
>IBM/RS6000, using "perl, version 5.001 Unofficial patchlevel 1m"):
> 0 0 0
> 1 1 2.4
> 2 2 4.8
> 3 3 7.2
>
Still there in 5.002beta1 on SunOS. Looks like the eval is triggering
a 'local/global' $i ...