walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
Looking at the YAML 1.1 spec, I see that anything matching this regexp:
is considered a boolean. I have the following structure in my .yaml file:y|Y|yes|Yes|YES|n|N|no|No|NO |true|True|TRUE|false|False|FALSE |on|On|ON|off|Off|OFF
I have the following code:- 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
#!/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::XSYAML::Syck$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'}} } ];
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.$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' } ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: YAML::XS, YAML::Syck and boolean values
by tobyink (Canon) on Jul 26, 2013 at 07:26 UTC | |
|
Re: YAML::XS, YAML::Syck and boolean values
by Loops (Curate) on Jul 26, 2013 at 06:05 UTC | |
|
Re: YAML::XS, YAML::Syck and boolean values
by Anonymous Monk on Jul 26, 2013 at 07:30 UTC | |
by Anonymous Monk on Apr 08, 2015 at 08:42 UTC | |
by Anonymous Monk on Apr 08, 2015 at 09:14 UTC | |
by Anonymous Monk on Apr 08, 2015 at 10:06 UTC | |
by jdporter (Paladin) on Apr 08, 2015 at 13:05 UTC | |
by Anonymous Monk on Apr 08, 2015 at 13:47 UTC |