|Think about Loose Coupling|
Action at a distanceby syphilis (Archbishop)
|on Nov 03, 2022 at 11:16 UTC ( #11147932=perlquestion: print w/replies, xml )||Need Help??|
syphilis has asked for the wisdom of the Perl Monks concerning the following question:
I've just been bitten by this annoying behaviour (using perls 5.30.0, 5.36.0, and probably others):
As you can see, in incrementing $x, both $y and $bi have also been incremented.
This behaviour can be avoided if I use the overloaded ++ operator instead of the binc() method call:
Of course, if I want to call a method for which there is no overloaded operation, then I have to workaround it some other way. It's probably not such a big deal, but there's no warning about the danger, and it can lead to some unexpected and puzzling results if you absent-mindedly fall into the trap.
I think I've struck it before ... something to do with the wonderful Copy-On-Write, IIRC.
Is there some way (apart from building perl without COW) to guard against getting bitten by this ?
Is it a bug in perl ?
Is it a bug in Math::BigInt ?
Whatever it is, it certainly doesn't DWIM.
Maybe it's just that this machine is one o' them quantum computers ;-)
Back to Seekers of Perl Wisdom