D
Dan Kirkwood
Here's a simple yaml output from the Ruby to_yaml method:
sample = { 'foo' => %w[ a b c ] }
puts sample.to_yaml
=>
sample = { 'foo' => %w[ a b c ] }
puts sample.to_yaml
=>
sample = { 'foo' => %w[ a b c ] }
puts sample.to_yaml
=>
This does *not* load in to the yaml module in Perl (changed to a
one-liner for brevity):
ruby -ryaml -e 'puts ({%{foo} => %w[a b c]}).to_yaml' | perl -MYAML
-0777 -e 'YAML::Load(<>)'
YAML Error: Invalid element in map
Code: YAML_LOAD_ERR_BAD_MAP_ELEMENT
Line: 3
Converting a similar structure using Perl produces yaml with the list
indented. My question is: which implementation is correct? Should the
a,b,c list be indented? The Ruby output is read properly by Ruby, but
not Perl. The Perl output is read properly by both.
This does *not* load in to the yaml module in Perl (changed to a
one-liner for brevity):
ruby -ryaml -e 'puts ({%{foo} => %w[a b c]}).to_yaml' | perl -MYAML
-0777 -e 'YAML::Load(<>)'
YAML Error: Invalid element in map
Code: YAML_LOAD_ERR_BAD_MAP_ELEMENT
Line: 3
Converting a similar structure using Perl produces yaml with the list
indented. My question is: which implementation is correct? Should the
a,b,c list be indented? The Ruby output is read properly by Ruby, but
not Perl. The Perl output is read properly by both.
Ruby's YAML support is further along than YAML.pm. The YAML
generated by Ruby's YAML module is correct for YAML 1.0. YAML.pm
just doesn't know how to parse it. See example 4.19 in the spec[1].
You might try Audrey Tang's YAML::Syck[2], which uses the same backend
as Ruby, thus is more likely to play nice with each other.
Signed with a very pricey horsehair brush,
_why
[1] http://yaml.org/spec/history/2004-01-29/2004-01-29.html#id2564419
[2] http://search.cpan.org/dist/YAML-Syck/
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.