alexkalderimis has asked for the wisdom of the Perl Monks concerning the following question:

I've just encountered a problem that has me absolutely flummoxed - I have some code that uses operator overloading to produce nested sets of objects, and on a smalll scale it works fine:
$logic = ($cA & $cB & $cC & $cD); say '$cA & $cB & $cC & $cD is :', $logic->as_string; >>> ((A and B and C and D or E) or F)
but if I try any more than 7 elements I get bizarre corrupted memory addresses in the objects: here are some examples:
Can't locate object method "as_string" via package "InterMine::PathQue +ry::ConstraintSet=HASH(0x87yt738)"
and InterMine::PathQuery::ConstraintSet=HASH(0x8737;=8) and InterMine::PathQuery::ConstraintSet=HASH(0x8ae23s0) and InterMine::PathQuery::ConstraintSet=HASH(0x8uu6sw8) you can see the code for the offending module here: http://pastebin.com/QN2sZN5G and the associated code here: http://pastebin.com/XwxDxJJH I have never seen anything like this before - any ideas out there from the Monks? Alex

Replies are listed 'Best First'.
Re: Corrupted Object memory addresses
by ikegami (Patriarch) on Jun 21, 2010 at 17:33 UTC

    As explained in the CB, the memory address wasn't corrupted, the reference was. It was replaced with a string, and modifications were made to that string. This surely occurred because of a missing dereference.

    Looking at the code you provided, I see

    $logic = ($cA & $cB & $cC & $cD);

    $logic is assigned a string or a number (depending on the values of $cA, $cB, $cC and $cD), but then you do

    $logic->as_string

    Needless to say, the random string or number you created is not an object, and the call fails.

    Judging by the value that does end up in $logic, you've got a second problem. $cA, $cB, $cC or $cD contains a object reference, but you're treating it as a bit string. This is what's corrupting the reference.

      Thanks for the comments - they certainly led me to the answer: I had already overloaded the & and | operators in one package, but I needed to do this to another as well. Thanks for your help.