in reply to Store hash in mysql

Why do you think you need to do this? Normally, one would design a proper database schema and store each field of the hash in an appropriate row in the database table. Now that person can leverage the power of the database, rather than have to use Perl and risk doubling their work. Perhaps you are using this for a web browser session? Because without knowing what it is exactly that you are wanting to do -- giving advice to break normal form is not the best advice one can give. Rather ... one should not answer your question but instead ask you why you think you need to do this.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Store hash in mysql
by smallvaluesof2 (Novice) on Jan 19, 2009 at 15:30 UTC

    I agree with Jeffa that in principle what you are asking to do sounds wrong. However, I don't know the circumstances and perhaps you need a temporary band-aid pending a better solution.

    In that case, you have a couple of options:

    1. Use Data::Dumper to flatten the hash into a scalar (string) and store the latter in a TEXT (or suitably large CHAR/VARCHAR) column and use eval to turn it back into a hash.
    2. Create an array of key value pairs (eg using each %hash), join them with a special char and store that in the text column so a simple split on the resultant string will give you the key, value array back which you can easily turn back into a hash.