Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Converting from Storable to YAML

by thezip (Vicar)
on Jan 21, 2011 at 21:41 UTC ( #883622=note: print w/ replies, xml ) Need Help??


in reply to Converting from Storable to YAML

Better still is to use JSON::XS.

use strict; use warnings; use JSON::XS; my $hash {}; ... fill up the hashref with stuff ... my $json = JSON::XS->new()->pretty(); my $json_text = $json->encode($hash); open(my $ofh, '>', $outfilename); print $ofh $json_text; close $ofh;

The stored format in the file is quite readable, and JSON::XS is uber-fast when compared to YAML and Storable.


What can be asserted without proof can be dismissed without proof. - Christopher Hitchens


Comment on Re: Converting from Storable to YAML
Download Code
Re^2: Converting from Storable to YAML
by Your Mother (Canon) on Jan 21, 2011 at 21:48 UTC

    JSON::XS--which I love--is harder to edit by hand, has less support for objects/etc, and is on par with Storable for speed. I think it can be faster for certain strings/sizes but I also recall Storable being better for others. Oh, and YAML::XS was not around when those benchmarks were done so it might well be on the same playing field since it's C beneath too.

    So, I recommend it too but I tend to personally use it for machine cases and Ajax only, never for human edited configuration, etc.

Re^2: Converting from Storable to YAML
by moritz (Cardinal) on Jan 21, 2011 at 21:57 UTC

    JSON and YAML fill two different needs.

    JSON is meant for data interchange between different languages, and can only handle the most basic data types (arrays, hashes, strings, numbers and undef, and only tree structures).

    YAML on the other hand also handles blessed references and self-referential constructs (ie. arbitrary object graphs).

    No wonder that JSON modules are faster than YAML modules, they do way less.

    When the feature set of JSON is sufficient, choosing JSON over YAML is a good idea (simpler format, easier to implement right, less chance of ambiguity). If not, not.

    There's also JSYNC, which tries to combine the advantages of both formats. I don't know how mature it is today.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://883622]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-10-01 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (31 votes), past polls