I want to save a hash as a packed string in a db, I get the pack part down ok, but I’m having a problem getting the hash back
test hash
my $hash = {
test_string => 'apples,bananas,oranges',
test_subhash => { like => 'apples' },
test_subarray => [ red, yellow, orange ]
}
I thought maybe I could use JSON:XS like in this example to convert the hash to a json string, and then packing the JSON string…
Thoughts on this approach?
Storable is capable of storing Perl structures very precisely. If you need to remember that something is a weak reference, etc, you want Storable. Otherwise, I’d avoid it.
JSON (Cpanel::JSON::XS) and YAML are good choices.
Usage:
I don’t know what you mean by “packing”. The string produces by Cpanel::JSON::XS’s
encode_jsoncan be stored as-is into aBLOBfield, while the string produced byCpanel::JSON::XS->new->encodecan be stored as-is into aTEXTfield.