in reply to freeze and thaw ?

Have you read the documentation provided in Storable? What parts do you have problems with?

The Storable package brings persistence to your Perl data structures containing SCALAR, ARRAY, HASH or REF objects, i.e. anything that can be conveniently stored to disk and retrieved at a later time.

"Persistence" means "Surviving things", in this case, surviving the end of the program. If you build a data structure in your program, you can store that data structure to disk using Storable.

Replies are listed 'Best First'.
Re^2: freeze and thaw ?
by cztmonk (Monk) on Jul 28, 2012 at 12:59 UTC

    I have trouble understanding the term "Serializing to memory", why not use "save to memory" ...

      I think "save" is more commonly used with nonvolatile storage, while "serialize" is commonly used to mean "transform a data structure to a string (or sequence of bytes)".

        Thanks again Corion for the explanation. As allways when learning a module, I made a sample program that uses it, and I understand it better now.

        #!/usr/bin/perl # Hash,use of keys and values inc. use Storable use strict; use warnings; use Data::Dumper qw(Dumper); use Storable qw(store retrieve freeze thaw); my %hash; my $hash; sub Dump { local $Data::Dumper::Terse = 1; local $Data::Dumper::Purity = 1; local $Data::Dumper::Deepcopy = 1; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; Data::Dumper::Dumper(@_); } # presize %hash (to a power of 2) keys(%hash) = 8; # create a hash with a list of key/value pairs %hash = ( '01' => 'data1', '02' => 'data2', '03' => 'data3', '04' => 'data4', '05' => 'data5', '06' => 'data6' ); # store hash store \%hash, 'store.txt'; # retrieve hash $hash = retrieve('store.txt'); # dump hash print Dump(\%hash); print "\n"; # freeze creates a binary image of a data structure, # and thaw takes that image and turns it back into a # copy of the original data structure. my $str = freeze \%hash; printf "Serialization of %%hash is %d bytes long.\n", length($str); print "\n"; # clone hash my %table_clone = %{ thaw($str) }; # dump hash print "This is your clone:\n"; print Dump(\%table_clone); exit;