A counter example using YAML file to store the data.

In this example we can see how to use YAML as data storage. How to load existing YAML file and how to create new one from data in the memory.

We can also see how accept a command line parameter using shift.

examples/counter_yml.pl

use strict;
use warnings;
use 5.010;

use YAML qw(LoadFile DumpFile);

my $name = shift or die "Usage: $0 NAME\n";

my $filename = 'counter.yml';

my $data = {};
if (-e $filename) {
    $data = LoadFile($filename);
}

$data->{$name}++;
say $data->{$name};

DumpFile($filename, $data);