You really want YAML::XS to behave more like YAML::Syck here? Because I think YAML::XS's behaviour is more correct than YAML::Syck's. Demonstration:

#!/usr/bin/env perl use strict; use warnings; use YAML::XS (); use YAML::Syck (); my $data = do { local $/; <DATA> }; print "With YAML::XS...\n"; my $xs = YAML::XS::Load($data); for my $person (@$xs) { print "$person->{name} is happy\n" if $person->{happy}; } print "With YAML::Syck...\n"; my $syck = YAML::Syck::Load($data); for my $person (@$syck) { print "$person->{name} is happy\n" if $person->{happy}; } __DATA__ - 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

YAML::Syck claims that Bob and Frank Johnson are happy!

It's true that the ${\$VAR1->[0]{'active'}} bits in the Data::Dumper output look funny, but that seems to be an optimization that YAML::XS is applying; using the same SV structure (if you don't know what an SV structure is, perlguts probably has more info than you want) to represent all booleans in the whole output data structure.

I can achieve a similar effect using Data::Alias (note that Data::Alias is broken in Perl 5.18):

#!/usr/bin/env perl use strict; use warnings; use Data::Alias; use Data::Dumper; my $false = !! 0; my $true = !! 1; my (@foo, @bar); alias $foo[0] = $false; alias $bar[0] = $false; alias $foo[1] = $true; alias $bar[1] = $true; print Dumper \@foo, \@bar;
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

In reply to Re: YAML::XS, YAML::Syck and boolean values by tobyink
in thread 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.