Search code examples
perlparsingtoml

How to parse simple toml in perl?


I need implement user friendly configuration file to my perl's script. I choose toml, but im not sure how working TOML parser.

backtest.toml file

strategies1 = [ neuralnet, BBRSI ];

script perl:

use TOML qw(from_toml to_toml);
use Data::Dumper;
my $toml = slurp("backtest.toml");
my $data = from_toml($toml);
print Dumper($data);
print Dumper($strategies1);

Solution

  • Check error use the code

    my ($data, $err) = from_toml($toml);
    unless ($data) {
        die "Error parsing toml: $err";
    }