Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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
    [erix]: yes, I got it :) It's close to where I live (Utrecht)
    [LanX]: Dutch royals usually spent their exiles on Berlin
    [erix]: well, dutch royals are germans, really
    [choroba]: Utrecht? Is that where we made the trip, LanX?
    [erix]: we should really dupm the lot, but I got no say in the matter :)
    [LanX]: yeah its a religious mafia , the only two big calvinist houses are dutch and prussian. ..
    [LanX]: choroba yes
    [erix]: Utrecht has a beautiful old center, and less mass-tourism than Amsterdam
    [erix]: next time, drop by :)
    [LanX]: religion is also the reason how the house of Hanover aquire the English throne, all other candidates on succession where catholics...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (12)
    As of 2017-12-15 16:36 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (439 votes). Check out past polls.