gmpassos has asked for the wisdom of the Perl Monks concerning the following question:
Soo, I tried to isolate the bug and make sample of it:
The BUGGED output is:{ package RecMy ; use strict ; sub rec { my $n = shift ; return if !$n ; rec( --$n ) ; my $local = "[$n] set" if ($n/3) !~ /\./ ; $local .= ' append' ; print "<$n> $local\n" ; } for(1..5) { print "--------------------- $_\n" ; rec(4); } }
But the right output should be:--------------------- 1 <0> [0] set append <1> append <2> append <3> [3] set append --------------------- 2 <0> [0] set append <1> append append <2> append append <3> [3] set append --------------------- 3 <0> [0] set append <1> append append append <2> append append append <3> [3] set append --------------------- 4 <0> [0] set append <1> append append append append <2> append append append append <3> [3] set append --------------------- 5 <0> [0] set append <1> append append append append append <2> append append append append append <3> [3] set append
And to produce the right output I have just changed one line of the code:--------------------- 1 <0> [0] set append <1> append <2> append <3> [3] set append --------------------- 2 <0> [0] set append <1> append <2> append <3> [3] set append --------------------- 3 <0> [0] set append <1> append <2> append <3> [3] set append --------------------- 4 <0> [0] set append <1> append <2> append <3> [3] set append --------------------- 5 <0> [0] set append <1> append <2> append <3> [3] set append
## changed from (bugged): my $local = "[$n] set" if ($n/3) !~ /\./ ; ## to (fine): my $local ; $local = "[$n] set" if ($n/3) !~ /\./ ;
Soo, why this happens? It seems that my() creates the same scalar 2 times? Or the scalar is not destroied after end the scope of the sub? Or this is a optimization bug? I think that this is a reference count bug, but I haven't looked the Perl CORE yet to really say that.
Note that the bug only happens if the interpolation exists, that is made by:
I saw the bug first on Perl-5.6.1, than I saw it on Perl-5.8.2 and Perl-5.8.3 too. Soo, wasn't patched yet!... if ($n/3) !~ /\./ ;
I will wait some advices from the monks before send it to perlbug...
Graciliano M. P.
"Creativity is the expression of the liberty".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: This is really a Perl BUG with my?! Need some advice...
by thelenm (Vicar) on Jan 24, 2004 at 04:39 UTC | |
by duff (Parson) on Jan 24, 2004 at 04:44 UTC | |
| |
|
Re: This is really a Perl BUG with my?! Need some advice...
by davido (Cardinal) on Jan 24, 2004 at 07:36 UTC | |
by ysth (Canon) on Jan 25, 2004 at 06:24 UTC | |
|
Re: This is really a Perl BUG with my?! Need some advice...
by asarih (Hermit) on Jan 24, 2004 at 04:37 UTC |