in reply to Converting from Storable to YAML

the simple Store/Retrieve is all I needed. -- Ah, the simple store/retrieve is not so simple.

My personal preference between YAML, Storable, and JSON is YAML. As for version of YAML, I'm not fussy so I use YAML::Any. That way I can use whatever YAML (XS, Old, other) that has been installed on the host system.

YAML handles a much wider range of data structures than JSON, as wide as Storable, and it won't blow up on you if you just happen to have a circularity in your data.

I prefer YAML over Storable, because YAML is human readable and machine/Perl version independent. The main issue with Storable is that the data is dumped exactly as Perl stores it in C, which means that it is machine specific and possibly Perl release specific. You can't assume that a file you dump on your machine will load properly on another machine.

Since Storable dumps in a format efficient for the computer and not a person, its output is not at all easy to inspect, if you are trying to figure out what went wrong. Finally, it is a bit fussy to test dumped data (did I get what I expected?) in an automated fashion because small details about the way a variable is handled during the life of the program (namely whether it was used as a string, number or both) can change the way a number is dumped.

Since JSON is also human readable, JSON is often pushed as the faster, more "hip" substitute for YAML, but there are some limitations that really make it only suitable for very simple kinds of data. Neither Storable or YAML face any of these limitations.

Replies are listed 'Best First'.
Re^2: Converting from Storable to YAML
by BrowserUk (Patriarch) on Jan 22, 2011 at 18:12 UTC

    This should be a tutorial++

Re^2: Converting from Storable to YAML
by mascip (Pilgrim) on Dec 03, 2012 at 21:39 UTC

    Thank you for such a clear tutorial !

    How does DBM::Deep compare to YAML::Any, for saving Hashes ?