in reply to Re: How to use packed binary data
in thread How to use packed binary data

I have now tested one example in the web address I gave in my last reply and all was fine.
I then tried to alter this so that the hash was defined as
$megalith{name} = 'Stonehenge';
and so on.

I found that I had to alter the freeze to
my $storedValues = freeze( \%megalith );
However, I then got the error
Reference found where even-sized list expected at 37
this line was the thaw line that I had put as
%megalith = thaw( $storedValues );
I have tried various things but so far failed to find an answer
can anyone explain how to correct this?
the full code is below

use strict "vars";
use Storable qw( freeze thaw );
### Create some values in a hash
my %megalith;
$megalith{name} = 'Stonehenge';
$megalith{mapref} = 'SU 123 400';
$megalith{location} = 'Wiltshire';
### Print them out
print "Initial Values: megalith = $megalith{name}\n" .
" mapref = $megalith{mapref}\n" .
" location = $megalith{location}\n\n";
### Store the values to a string
my $storedValues = freeze( \%megalith );
### Reset the variables to rubbish values
$megalith{name} = 'Flibble Flabble';
$megalith{mapref} = 'XX 000 000';
$megalith{location} = 'Saturn';
### Print out the rubbish values
print "Rubbish Values: megalith = $megalith{name}\n" .
" mapref = $megalith{mapref}\n" .
" location = $megalith{location}\n\n";
### Retrieve the values from the string
%megalith = thaw( $storedValues );
### Display the re-loaded values
print "Re-loaded Values: megalith = $megalith{name}\n" .
" mapref = $megalith{mapref}\n" .
" location = $megalith{location}\n\n";
exit;

Replies are listed 'Best First'.
Re^3: How to use packed binary data
by dave_the_m (Monsignor) on Jan 24, 2005 at 12:31 UTC
    thaw returns a reference to a hash, so you need to dereference it if you want to assign it to a hash variable:
    %megalith = %{thaw( $storedValues )};

    Dave.

      Many thanks - all now works well. One day I will understand such things - or will I??