in reply to YAML::Syck serializing Dump into single line

YAML is a whitespace sensitive format. Therefore expecting it to serilize to a single line is contradictory to its inherent nature.

---
$world=~s/war/peace/g

  • Comment on Re: YAML::Syck serializing Dump into single line

Replies are listed 'Best First'.
Re^2: YAML::Syck serializing Dump into single line
by ferreira (Chaplain) on Jan 25, 2007 at 13:05 UTC

    What cLive ;-) probably meant was for some option to make the YAML::Syck dumper spit inline sequences and maps, as in

    { a : [ 1, 2, 3], b : { b_a: "a\n" } }
    instead of the usual multi-line representation (which uses a lot of indentation indeed).
    --- a: - 1 - 2 - 3 b: b_a: "a\n"

    I am not sure of what exactly syck can do, but it is very possible that even if there's such option in the underlying library, it is not currently exposed by the binding code implemented by YAML::Syck. The module is very immature yet, but fast as hell (for things it can grok).

      Perhaps JSON::Syck (which uses libsyck to spit out more JSON-friendly YAML) may be more what he's looking for.

      $ perl -MJSON::Syck=Dump -le 'print JSON::Syck::Dump( { a => { b => "c +", d => [qw/1 2 3/] } } )' {"a":{"b":"c","d":["1","2","3"]}}

      "The module is very immature yet, but fast as hell (for things it can grok)."

      Indeed! I benchmarked it against reading/writing a hashref of arrayref of hashrefs against XML::Simple, and it created files three times faster, and parsed them nine times faster. Unfortunately, the context I'm currently working in involves one line of data transfer only, so I need to work around the new lines if I'm going to work on integrating it.

      I think I'll have to examine the JSON::Syck implementation when I finally get round to trying to implement this. I like YAML because, unlike XML, it actually makes sense to me :)