Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: References and state-saving

by BlueLines (Hermit)
on Jan 13, 2001 at 04:16 UTC ( [id://51514]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://51514]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-26 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found