in reply to Packing hashes or complex structures?

Could we pack a hash?
Well, yes. pack takes a format and a list of values, and it's rather trivial to turn a hash into a list of values (although you probably want a deterministic order). You probably want something like (untested):
my %hash = make_me_a_hash; my @key_order = qw[key1 key2 key3 key4]; my $packformat = "ABCDEFGH"; my $packed_str = pack $packformat, map {$_, $hash{$_}} @key_order;
And you should be able to unpack that as:
my %hash = unpack $packformat, $packed_str;

Replies are listed 'Best First'.
Re^2: Packing hashes or complex structures?
by theantler (Beadle) on Mar 24, 2010 at 16:11 UTC
    That template does not look valid .. But, thats a cool way to do it with map and spitting out a list, I had not though it that way. I am going to try that! Thanks folks ..