An interpolated reference is just a string. There is no way to change it back to a real reference (well... you could probably hack around with XS or Inline::C) and if it was the last reference to an object the object will get lost.

The only problem I have with that is why you would do something like this anyway:

my $ref = Object->new(); $ref = "$ref"; # overwrite $ref: destroy object
Is there any use for this? If you really want a stringified reference, you can always make a copy (ie:)
my $ref = Object->new(); my $refstring = "$ref"; # keep object in $ref
Update: Just a reminder: you can not restore a pointer to a destroyed object without serious memory leeks / core dumps and other unpleasantness, so IF the object is still in memory, you still have another reference laying about somewhere - then you CAN get your reference back.
#!/usr/bin/perl -w use strict; use vars qw($ref); $ref = [1,2,3,4]; print join(',',@$ref)."\n"; my $string = "$ref"; #print join(',',@$string)."\n"; # this does not work my $getref = unstringify($string) || die "Cannot find ref!"; print join(',',@$getref)."\n"; sub unstringify { # works only on globals in package main ! # but you could also use another hash # ( instead of %main:: ) my $string = shift; for (keys %{main::}) { my $value; next unless $value = ${${main::}{$_}}; next unless ref($value); next unless $value eq $string; # implicit stringification return $value; } return; }

This is ofcourse a terribly hack, you'd be a lot better of if you store your references somewhere where you can retrieve them easier.

-- Joost downtime n. The period during which a system is error-free and immune from user input.

In reply to Re: Recovering References from Interpolation by Joost
in thread Recovering References from Interpolation by PetaMem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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.