in reply to Re^4: Control Structures
in thread Control Structures
The first time you run it with $arg = 0, you will get the expected result. The second time through with $arg = 0, you will find the Other::Package object from last time in $object and it will not get a fresh Other::Package object assigned to it. So, if you never put anything in $object when the conditional is false, you won't actually see the bug.sub sticky { my $arg = shift; my $object = Some::Package->new() if $arg; $object ||= Other::Package->new(); }
I have personally seen people lose days debugging problems caused by this, and have heard stories about it happening in other companies too. It's hard to see, it's very hard for people to fully understand, and it really happens in production code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Control Structures
by glwtta (Hermit) on May 12, 2005 at 05:26 UTC | |
by perrin (Chancellor) on May 12, 2005 at 05:37 UTC |