my $ref = Object->new();
$ref = "$ref"; # overwrite $ref: destroy object
####
my $ref = Object->new();
my $refstring = "$ref"; # keep object in $ref
####
#!/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;
}
####
--
Joost downtime n. The period during which a system
is error-free and immune from user input.