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}) }
|
|---|
| 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 |