Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

YAML

---
people:
  Bar:
    phones:
      - 345
      - 678
    title: CEO
  Baz: NA
  Foo:
    phone: 123
#!/usr/bin/perl
use strict;
use warnings;

use YAML qw(DumpFile);

my $data_structure = {
    people => {
        Foo     => {
                phone => '123',
        },
        Bar     => {
            phones => [
                    '345',
                    '678',
            ],
            title => 'CEO',
        },
        Baz     => 'NA',
    }
};

DumpFile 'data.yml', $data_structure;

#!/usr/bin/perl
use strict;
use warnings;

use YAML qw(LoadFile);
my $data = LoadFile('data.yml');
print "$data->{people}->{Foo}->{phone}\n";          # 123
print "$data->{people}->{Bar}->{phones}->[0]\n";    # 345
print "$data->{people}->{Baz}\n";                   # NA