YAML is primarily used as a configuration file that people write and the program reads, but it can be used for data serialization as well. In addition, especially when writing tests, there are other cases as well when we would like to save a data structure as a YAML file.

examples/save_yaml.pl

use strict;
use warnings;
use YAML qw(DumpFile);

my %data = (
    name => 'Foo Bar',
    email => 'foo@bar.com',
    ids   => [12, 23 ,78],
);

DumpFile('data.yml', \%data);

The result will look like this:

examples/data/data.yml

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