in reply to Re: References and state-saving
in thread References and state-saving

Storable makes this much easier than Data::Dumper. Here's a sample using Data::Dumper:
#!/usr/bin/perl -w use Data::Dumper; my %hash = ('foo' => 'bar', 'camel' => 'beast', 'bug' => 'spray'); #dump the structure open (FILE, '>/tmp/hash') or die "$!\n"; print FILE Dumper(\%hash); close FILE; #recreate the structure open (FILE,'/tmp/hash') or die "$!\n"; my $data = do { local $/; <FILE> }; my %newhash = %{eval $data};
And here's the same thing with Storable:
use Storable; store \%hash, '/tmp/hash'; my %newhash = %{retrieve('file')};


BlueLines

Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.

Replies are listed 'Best First'.
Re: Re: Re: References and state-saving
by chipmunk (Parson) on Jan 13, 2001 at 21:25 UTC
    Here's a sample using Data::Dumper, that doesn't needlessly write the data structure to a temporary file:
    #!/usr/bin/perl -w use Data::Dumper; my %hash = ('foo' => 'bar', 'camel' => 'beast', 'bug' => 'spray'); my %newhash = %{ eval Dumper \%hash };
      Ahh, i didn't fully understand the start of the thread. I assumed that when Guildenstern wanted to save the state, he wanted to do so throughout seperate incantations of his program. I see now the he actually only need the state to be accessed in the same incantation. Sorry :-)

      BlueLines

      Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.