in reply to Re^3: freeze and thaw ?
in thread freeze and thaw ?
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;
|
|---|