persistent object in perl

Austin Godber plug-discuss@lists.plug.phoenix.az.us
Thu, 01 May 2003 13:20:13 -0700


I have tried this:

$Data::Dumper::Purity = 1;
open(FILE,"> $file") || die "Can't open $file:$!";
print FILE Data::Dumper->Dump([\$G],['*G']);
close FILE || die "Can't close $file:$!";

where $G is a graph of type Graph::Directed.  This results in a text 
file that looks reasonably like my data.

Then I try to read it in with something like this:

do $file || die "Can't recreate tvinfo: $! $@";

or this:

open(FILE,$file) || die "Can't open $file: $!";
undef $/;
eval <FILE>;
die "Can't recreate object from $file: $@" if $@;

In both cases it gets read in just fine, that is there are no errors. 
But when I try to use the object just as I had before, for instance:

my @V = $G->vertices;

I get the following result:

Can't call method "vertices" on unblessed reference at read-dump.pl line 14.

So I try to bless $G:

bless ($G, Graph::Directed);

and I now get:

Not a HASH reference at /usr/lib/perl5/site_perl/5.8.0/Graph/Base.pm 
line 96.

So now I am stuck.  I have also tried Storage, with no luck.

Austin

PS - I think at this point I am just going to write the graph to a 
textfile by hand and read it by hand, but I imagine there is a way to do 
this.

Bill Nash wrote:
> Data::Dumper may be what you're looking for.
> 
> - billn