incorrect yaml?

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
=>
 
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
=>
---
foo:
-a
-b
-c

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.

I've dug thru the yaml.org spec, but can't find any reference that
tells me which is correct..

Using Redhat Enterprise Linux 4, ruby 1.8.5, perl 5.8.8 w/YAML.pm 0.62
 
R

Rimantas Liubertas

Here's a simple yaml output from the Ruby to_yaml method:
sample = { 'foo' => %w[ a b c ] }
puts sample.to_yaml
=>

$ irb
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> sample = {'foo' => %w[a b c]}
=> {"foo"=>["a", "b", "c"]}
irb(main):003:0> puts sample.to_yaml
---
foo:
- a
- b
- c
=> nil
irb(main):004:0> sample.to_yaml
=> "--- \nfoo: \n- a\n- b\n- c\n"


Regards,
Rimantas
 
W

_why

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/
 
D

Dan Kirkwood

Ahh.. Thanks, why.. That's exactly the information I was looking
for. I'll try YAML::Syck. -dan

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/
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top