Incorrect yaml?

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

···

--
Posted via http://www.ruby-forum.com/.

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

--
Posted via http://www.ruby-forum.com/.

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
--
http://rimantas.com/

Rimantas, please see my *second* post. First one got cut off.. thanks..

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] YAML-Syck-1.34 - Fast, lightweight YAML loader and dumper - metacpan.org

···

On Tue, Jan 09, 2007 at 06:37:20AM +0900, Dan Kirkwood wrote:

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.

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

···

On 1/8/07, _why <why@ruby-lang.org> wrote:

On Tue, Jan 09, 2007 at 06:37:20AM +0900, Dan Kirkwood wrote:
> 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] YAML-Syck-1.34 - Fast, lightweight YAML loader and dumper - metacpan.org