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):
And you should be able to unpack that as: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;
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 |