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;

In reply to Re^4: freeze and thaw ? by cztmonk
in thread freeze and thaw ? by cztmonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.