On Sat, 10 Dec 2005, mikshir wrote:

> I have YAML documents generated in Perl and Python that I process with
> Ruby.
>
> Problem: Ruby wants to auto-interpret boolean flagged words, example:
>
> ---
> words:
>  - yes
>  - put
>  - it
>  - on
>  - the
>  - off
>  - setting
>
> gets loaded in Ruby as
>
> [true, "put", "it", true, "the", false, "setting"]
>
> Basically the latest Perl and Python YAML modules I could find won't
> quote some of the words that Ruby's YAML would. (Things like on, off,
> yes, no, +) Perhaps they conform to a different version of the YAML
> spec. I find the incompatibility a bit frustrating.  I can and have
> easily hacked the other modules to do the compatible thing but there
> are political admin maintenance issues surrounding my patching all the
> company computers with this.
>
> I'll not comment right now on whether I think it was a good idea to
> flag these items as special to begin with.  I'd just like to know if
> there's a simple module over-ride hack or module parameter setting that
> I can set or clip into my scripts to deal with this problem.
>
> Thanks.

why not simply conform to the spec? :

     harp:~ > cat a.rb
     doc = <<-yaml
     ---
     "words":
      - "yes"
      - "put"
      - "it"
      - "on"
      - "the"
      - "off"
      - "setting"
     yaml

     doc = STDIN.read unless STDIN.tty?

     require "yaml" and y(YAML::load(doc))


     harp:~ > ruby a.rb
     words:
     - "yes"
     - put
     - it
     - "on"
     - the
     - "off"
     - setting


     harp:~ > ruby a.rb|ruby a.rb
     words:
     - "yes"
     - put
     - it
     - "on"
     - the
     - "off"
     - setting


as you can see these words need to be quoted to be handled correctly -
basically the error is both in the person(s) writing the docs and in the other
decoders.  i'll bet a quoted "yes" or "no" works in perl and python decoders
too though.

regards.

-a
-- 
===============================================================================
| ara [dot] t [dot] howard [at] noaa [dot] gov
| all happiness comes from the desire for others to be happy.  all misery
| comes from the desire for oneself to be happy.
| -- bodhicaryavatara
===============================================================================