Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: References and state-saving

by boo_radley (Parson)
on Jan 13, 2001 at 03:31 UTC ( [id://51504]=note: print w/replies, xml ) Need Help??


in reply to References and state-saving

Isn't this the kinda thing data::dumper's for?

Replies are listed 'Best First'.
Re: Re: References and state-saving
by BlueLines (Hermit) on Jan 13, 2001 at 04:16 UTC
    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.
      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://51504]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found