in reply to Re: overload conflict between * and *= (as an example)
in thread overload conflict between * and *= (as an example)

yeah, this took care of it, thanks. I had read that part of the perldoc before, but I could not imagine how this could be relevant, but looking at the section again, lit the light for me;-)
And any suggestion as to why the rather inconspicious and innocent $test->{obj} = $N; can screw up the entire short program? I guessed that, if Perl would consider the "=" overloaded, it had to work only on lvalues, but the offending $N here is a rvalue, so, why does this produce a reaction at all?

Replies are listed 'Best First'.
Re^3: overload conflict between * and *= (as an example)
by tobyink (Canon) on Feb 27, 2012 at 18:13 UTC

    The reason is that with numbers you can do this:

    my $a = 1; my $b = $a; $a++; $b++; say $a; # says "2" say $b; # says "2"

    But if $a and $b are overloaded references to numbers, then they refer to the same object, so you've actually incremented the same object twice. $a and $b are both 3.

    Perl forces you to deal with (or at least acknowledge that you've thought about) this problem by in certain circumstances forcing you to provide an overload for "=".