Hi,
I've just been bitten by this annoying behaviour (using perls 5.30.0, 5.36.0, and probably others):
>perl -MMath::BigInt -wle "$bi = Math::BigInt->new(10); $x = $bi; $y = + $bi; $x->binc(); print $x; print $y; print $bi;" 11 11 11
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:
>perl -MMath::BigInt -wle "$bi = Math::BigInt->new(10); $x = $bi; $y = + $bi; $x++; print $x; print $y; print $bi;" 11 10 10
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 ;-)

Cheers,
Rob

In reply to Action at a distance by syphilis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.