Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

How to recover a reference from a stringified reference?

by NoamT (Initiate)
on Mar 21, 2002 at 14:16 UTC ( [id://153321]=perlquestion: print w/replies, xml ) Need Help??

NoamT has asked for the wisdom of the Perl Monks concerning the following question: (references)

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

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

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How to recover a reference from a stringified reference?
by knobunc (Pilgrim) on Mar 21, 2002 at 15:11 UTC

    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.

Re: How to recover a reference from a stringified reference?
by Fletch (Bishop) on Mar 22, 2002 at 03:04 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://153321]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-26 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found