Forgive me if I have overlooked some documentation on this.

Looking at the YAML 1.1 spec, I see that anything matching this regexp:

y|Y|yes|Yes|YES|n|N|no|No|NO |true|True|TRUE|false|False|FALSE |on|On|ON|off|Off|OFF
is considered a boolean.

I have the following structure in my .yaml file:
- name: Bob Johnson active: true happy: false - name: Bill Johnson active: true happy: true - name: Frank Johnson active: false happy: false - name: George Johnson active: false happy: true
I have the following code:
#!/usr/bin/env perl use strict; use warnings; use YAML::XS qw(LoadFile); use Data::Dumper; my $data = LoadFile('/tmp/test.yaml'); print Dumper($data);

The code for YAML::Syck is the same other than the fact that I am using YAML::Syck rather than YAML::XS.

Here are the results from each:

YAML::XS
$VAR1 = [ { 'name' => 'Bob Johnson', 'active' => 1, 'happy' => '' }, { 'happy' => ${\$VAR1->[0]{'active'}}, 'active' => ${\$VAR1->[0]{'active'}}, 'name' => 'Bill Johnson' }, { 'name' => 'Frank Johnson', 'active' => ${\$VAR1->[0]{'happy'}}, 'happy' => ${\$VAR1->[0]{'happy'}} }, { 'active' => ${\$VAR1->[0]{'happy'}}, 'name' => 'George Johnson', 'happy' => ${\$VAR1->[0]{'active'}} } ];
YAML::Syck
$VAR1 = [ { 'active' => 'true', 'happy' => 'false', 'name' => 'Bob Johnson' }, { 'name' => 'Bill Johnson', 'happy' => 'true', 'active' => 'true' }, { 'active' => 'false', 'happy' => 'false', 'name' => 'Frank Johnson' }, { 'name' => 'George Johnson', 'happy' => 'true', 'active' => 'false' } ];
The values from YAML::Syck are fine with me, somewhat. I was hoping for 1/0, but no big deal really, since true/false will evaluate fine. However, the results from YAML::XS are not exactly what I was expecting. I was hoping for each key to have its own value, not for keys to point to the values of other keys, which is what it seems that this is doing. Is there some way with YAML::XS to have boolean values? It seems to me that if a key has the same value as another key, then that key's value just becomes a reference for the other key's value.

In reply to YAML::XS, YAML::Syck and boolean values by walkingthecow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.