Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://883622]
help
Chatterbox?
[atcroft]: james28909: What about October 5, 1582?
[stevieb]: atcroft: "Make both hands into fists..."... is something my Ma taught me in our native lang, but I was to ignorant and young to pay attention. Thanks for that :)
[atcroft]: stevieb: Sad to say that I only recently learned that particular trick, but I have since found it very useful.... :)
[james28909]: ill be back with a solution eventually
[stevieb]: it's a reminder to re-inforce it :P
[atcroft]: james28909: That particular questions was a bit of trick, actually (depending on the country you are in). More interesting is, if you are trying to subtract from an epoch time, for instance, you might have to consider when/if DST occurs for a location,
[atcroft]: because you may have to adjust the number of seconds you change from an epoch from 86400 (not to mention leap seconds)....
[atcroft]: james28909: Although if your program is using a database, you might be able to "pass the buck" to the database and ask it to do the date change for you....

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2017-04-29 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.