Hi Shlomo.

> > You probably know that the construct:
> > my <variable> = <something> if <condition>;
> > is problematic.
>
> Why problematic (other than cases where programmer is
> confused in order of execution)?


Because if the condition is not true, the behavior is undefined. The
variable was not 'really' declared, and using it afterward is on your own
risk.

The Perl documentation states that if the condition is not true, there is
not guaranty what will be inside this variable.

In the bug that I found, the code was similar to:
my @sites = Sites->load if $have_sites;
push @sites, @others;

turn out when $has_sites was false, @sites array remembered the last call
final value. so on the next call I got duplicated values inside @sites. and
the call after that I got triple. and so on.

Shmuel.
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to