YAML is a common file format to hold configuration information that is easily readable and writable by humans.

But how do you read theem in you Perl script?

For example we have this YAML file:

examples/data/data.yml

---
email: foo@bar.com
ids:
  - 12
  - 23
  - 78
name: Foo Bar

examples/read_yaml.pl

use strict;
use warnings;
use YAML qw(LoadFile);
use Data::Dumper qw(Dumper);

my $filename = shift or die "Usage: $0 YAML-FILE\n";

my $data = LoadFile($filename);

print Dumper $data;

The output of Dumper looks like this:

$VAR1 = {
          'ids' => [
                     '12',
                     '23',
                     '78'
                   ],
          'name' => 'Foo Bar',
          'email' => 'foo@bar.com'
        };