R – get ARRAY(0x8470d6c) instead of a list from the YAML configuration

perlyaml

I have this YAML file:

name: Firas
dirs: [/bin/, /home/phiras/]

I am using YAML::Syck in perl to parse this file, and I have a problem with accessing dirs items. my code is:

#!/usr/local/bin/perl

use strict;
use warnings;
use YAML::Syck;
use ConfigLoader;
use Data::Dumper;

my $conf = LoadFile("myconf.yml") || die("Error: Open config file \n");

print $conf->{name}, "\n";

my @dirs = $conf->{dirs};

print Dumper @dirs;
foreach(@dirs){
        print "$_\n";
}

the output is :

    Firas
    $VAR1 = [
              '/bin/',
              '/home/phiras/'
            ];
    ARRAY(0x8470d6c)

as you can see the loop is printing one item and it is considered as array. am I doing it in the right way?

Best Answer

I think the problem is that $conf->{dirs} is an arrayref, not an array. Try this:

my @dirs = @{$conf->{dirs}};
Related Topic