in reply to Re: Recover a path from a config file
in thread Recover a path from a config file

use strict; use warnings; #use Data::Dumper; my ($content); { open my $fh,'<','work.conf' or die $!; local $/; $content = <$fh>; } my $config = eval $content; #print Dumper(\$config); print 'Licences: ' . join ',', @{$config->{licence}};

Update: to look at the first and second specifically, try the following.

printf "First licence: %s\n", ${$config->{licence}}[0]; printf "Second licence: %s\n", ${$config->{licence}}[1];

Updated again: if the contents of the licence tag could be either a single value or a list of values, you will need to use the ref command to tell the difference.

use File::Spec::Functions qw/catfile/; ... if (ref($config->{licence}) eq 'ARRAY') { foreach my $lfile (@{$config->{licence}}) { print catfile($::folder,$lfile) } } else { print catfile($::folder,$config->{licence}) }
But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Replies are listed 'Best First'.
Re^3: Recover a path from a config file
by Chaoui05 (Scribe) on Jun 07, 2016 at 10:33 UTC

    Hey GotToBTru,

    Thanks for reply!! Your approach is pretty good. I would like to have same level in "Hash".

    Condition is very useful in this particular cas namely when tag can be either a single value or a list.

    *****Lost in translation****TIMTOWTOI****