in reply to resurrecting objects?

Well, only you can know what it means for two of your objects to be "equal", so the best way would be for you to implement a compare method within the object that would compare the attributes of the object with a different object. You could then do something like this:

if ($obj1->compare($obj2)) { # ... }

Another nice touch would be to use overload to redefine the == or eq operators like this:

use overload '==' => \&compare;

You can then write code like this:

if ($obj1 == $obj2) { # ... }

But it's still your compare method that is actually being called.

--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

Replies are listed 'Best First'.
Re: Re: resurrecting objects?
by perchance (Monk) on May 03, 2001 at 15:01 UTC
    I understand and we may implement it as proposed (have never overloaded
    in Perl before :-), but what I wanted was to get the reference back from the
    string that describes it, I know I may be missing something.
    Is it possible to backtrack in this way, or is the conversion conducted
    by the interpolation irreversible?

    Thanks,
    me

    ---Strange Currencies

      OK. I think I understand now. Your problem is that somewhere along the line you have "stringified" your object and turned the reference into a string. There's no way (that I know of) to undo this, so you'll need to find out where the stringification takes place and fix that piece of code. You're looking for somewhere where the reference is quoted unnecessarily.

      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

        I suspect that you could find the pointer again using unpack with the -P option to follow a pointer back to where the object is (hopefully) still in existence.

        It would take a serious hacker to successfully do this, and only the insane would consider it. I say this with full knowledge that this may motivate you to demonstrate what a wizard you are by going out and doing it. What is worse is that I feel no remorse in saying this, I am confident that you of all people are capable of doing it, and I am sure you would find it fun in a crazy sort of way.

        Aren't I a jerk when I want to be? :-P

      Would I be correct in guessing that your stringified reference comes out of a hash key? If so, you may want to have a look at Tie::RefHash. Otherwise, just create a hash table mapping pointer strings back to their original objects, as tye suggests.

      If, however, by resurrecting, you mean reclaiming an object that was deleted by garbage collection (ie. refcount went to 0), this would be a very dangerous and unwise thing do, for reasons that are fairly obvious.

         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print