I'm not sure why you want to do this, but if you really need it, ignore the answers that use the tricks to look into memory. They'll only cause you problems.
Why do you want to do this? There's probably a better design. Where are you getting that stringified reference from.
Let's say you need to do it for whatever reason. First, create a registry of objects where the hash key is the stringified form, and the value is a weakened reference:
use Scalar::Util qw(weaken);
my $array = [ ... ];
$registry{ $array } = $array;
weaken( $registry{ $array } ); # doesn't count toward ref count
Now, when you have the stringified form, you just look it up in the hash, checking to see that it's still a reference:
if( ref $registry{$string} ) { ... }
You could also try Tie::RefHash and let it handle all of the details of this.
There is a longer example of this in Intermediate Perl.
Dumper( $b )
. Obviously you want towarn
. When do you want towarn
? In most places where I can stringify$a
, I also have$a
to dump. – Alienoreval $thing
. Of course this depends on the way it was stringified. If you used Data::Dumper or Data::Dump, justeval
ing it will recreate your objects. – Winters"$ref"
will give you"ARRAY(0x1234...)"
, and not"[]"
. – Winters"ARRAY(0x1234...)"
version. :) – Operculum