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

Re: Converting from Storable to YAML

by thezip (Vicar)
on Jan 21, 2011 at 21:41 UTC ( [id://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 (Archbishop) 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 04:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found