in reply to YAML::XS, YAML::Syck and boolean values
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;
|
|---|