Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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

Replies are listed 'Best First'.
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.

Re^2: Converting from Storable to YAML
by Your Mother (Chancellor) 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://883622]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2017-02-27 00:08 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (376 votes). Check out past polls.