syphilis has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I've just been bitten by this annoying behaviour (using perls 5.30.0, 5.36.0, and probably others):
This behaviour can be avoided if I use the overloaded ++ operator instead of the binc() method call:
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 ;-)
Cheers,
Rob
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.>perl -MMath::BigInt -wle "$bi = Math::BigInt->new(10); $x = $bi; $y = + $bi; $x->binc(); print $x; print $y; print $bi;" 11 11 11
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.>perl -MMath::BigInt -wle "$bi = Math::BigInt->new(10); $x = $bi; $y = + $bi; $x++; print $x; print $y; print $bi;" 11 10 10
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 ;-)
Cheers,
Rob
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Action at a distance
by hv (Prior) on Nov 03, 2022 at 12:07 UTC | |
Re: Action at a distance
by haj (Vicar) on Nov 03, 2022 at 15:50 UTC | |
by syphilis (Archbishop) on Nov 04, 2022 at 12:52 UTC | |
Re: Action at a distance (updated)
by LanX (Saint) on Nov 03, 2022 at 11:35 UTC | |
by syphilis (Archbishop) on Nov 03, 2022 at 12:42 UTC | |
by ikegami (Patriarch) on Nov 03, 2022 at 14:29 UTC | |
by LanX (Saint) on Nov 03, 2022 at 15:05 UTC | |
by ikegami (Patriarch) on Nov 03, 2022 at 14:15 UTC | |
by LanX (Saint) on Nov 03, 2022 at 14:24 UTC | |
by ikegami (Patriarch) on Nov 03, 2022 at 14:30 UTC | |
Re: Action at a distance
by afoken (Chancellor) on Nov 03, 2022 at 15:36 UTC | |
by LanX (Saint) on Nov 03, 2022 at 15:51 UTC | |
Re: Action at a distance
by ikegami (Patriarch) on Nov 03, 2022 at 14:41 UTC | |
by karlgoethebier (Abbot) on Nov 03, 2022 at 19:26 UTC | |
by LanX (Saint) on Nov 03, 2022 at 19:49 UTC |
Back to
Seekers of Perl Wisdom