in reply to Re: How to change referent of lexical reference?
in thread How to change referent of lexical reference?

See above. This isn't a question of comparison, but rather that I really don't want two objects that have the same data.
  • Comment on Re: Re: How to change referent of lexical reference?

Replies are listed 'Best First'.
Re: Re: Re: How to change referent of lexical reference?
by tilly (Archbishop) on Sep 22, 2003 at 04:41 UTC
    The general part of the question (how to recognize other data structures that mirror data) is hard.

    But causing one reference to a data structure to be the same as another is fairly easy:

    sub some_sub { $_[0] = $bar; }
    The trick is that while variables are in @_ they are passed in by reference. If you don't make copies, then you can modify the passed in values. This API may surprise...
      As I mentioned in response to someone else, it doesn't work in this particular case, because of the way Storable calls the STORABLE_thaw() method.
        I could wish for a clearer description of your problem than, it doesn't work.

        What doesn't work? Does the solution not provide a complete answer? I said that it didn't, and said what the unaddressed hard bit is. Does the technique do what I said it would? Yes. Does the technique presented show something useful to what you want to do? I believe so. Come up with a way of comparing the data structure that you are passed in with others that you have seen and then alias it by force. The hard part is doing that tracking. Does this have anything to do with how Storable implements its thaw method? Not that I can see.

        Given how long my day has been I am not going to write the code for a full implementation. But I assure you that it is fairly straightforward to take the incoming structure, stringify using Storable (preferably with the canonical flag set to true), use Digest::MD5 to produce a short key, and look in a hash of other thawed structures for your element. Making this recursive to catch substructures is also doable.

        But I haven't implemented this tonight, so this post has nothing that will work out of the box.