Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

How to recover a reference from a stringified reference?

by Zombie NoamT (Initiate)
on Mar 21, 2002 at 14:16 UTC ( #153321=categorized question: print w/replies, xml ) Need Help??
Contributed by Zombie NoamT on Mar 21, 2002 at 14:16 UTC
Q&A  > references


I have a string which is the stringification of an object reference, e.g.

How can I recover from this an actual reference, so that (e.g.) I'll be able to call the object's methods?

Answer: How to recover a reference from a stringified reference?
contributed by knobunc

The problem with doing this is that it bypasses perl's reference-counting memory management scheme. If you could ref-ify a stringified ref, you'd be getting a new reference to something without incrementing that thing's reference count. That means you could still have "live" references to an object which perl has already deallocated due to its reference count reaching zero.

Now that you know all that, if you really still want to reconstitute a reference from a string (and have no fear of the potentially nasty consequences) try the Devel::Pointer module.

See this post by Ovid for more information on references.

Answer: How to recover a reference from a stringified reference?
contributed by Fletch

One additional point: If your refs are getting stringified because you're using them as keys to a hash, you might want to look into Tie::RefHash, which will avoid that problem.

Please (register and) log in if you wish to add an answer

  • 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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (5)
    As of 2018-08-14 10:46 GMT
    Find Nodes?
      Voting Booth?
      Asked to put a square peg in a round hole, I would:

      Results (148 votes). Check out past polls.