"Ben Tilly" <ben_tilly / hotmail.com> wrote: > ts <decoux / moulon.inra.fr> wrote: > > > > >>>>> "L" == Leo Razoumov <see_signature / 127.0.0.1> writes: > > > >L> I do not understand why "my" is too complex to a user. It has been in > >L> Perl for years and no one complained of its complexity. > > > > OK, explain me this result > > > >pigeon% cat a.pl > >#!/usr/bin/perl -wl > >use strict; > >sub toto > >{ > > my $i = shift; > > my $m = $i if !($i % 5); > > $m++; > > print "$i : $m"; > >} > > > >for (my $i = 0; $i < 15; $i++) { > > toto($i); > >} > > Ah, my favorite bug! > > The implementation of my in Perl has a stupid optimization. > Perl allocates space for the my once, and then reuses the > space later, depending on a runtime initialization to know > whether it needs to reinitialization. With the one line > conditional it may skip this needed initialization, leading > to the value from a previous call being preserved. Holy COW! I just grepped the Perl code I've written over the past couple of years and I've used this idiom hundereds of times. . . . Mostly in places where - if this bug has been manifesting - a "re-used" value from a previous iteration of the function would almost certainly gone undetected, but the data output by the program would have been "wrong", in subtle ways. . . . Shudder. Thanks Guy & Ben for the heads up. Maybe I'll be switching to Ruby sooner than I thought. =) Bill