in reply to Recover a path from a config file

I did that now and it works:

In my folder, in config.file

$::folder = 'E:\FOLDER\Test\WEB';
And in my test.file :
use File::Spec::Functions qw/catfile/; my $filename = catfile($::folder, $config->{licence});

And it works fine.

Thanks all

PS: I have now my config.file with thoses little changes, at the beginning of this one :

my $folder = 'E:\FOLDER\Test\WEB'; { license => [ 'kit-licence.zip', 'kit-work.zip' ], programs => [..

I have this simple question. How can i do if i want to get first licence or the second doing that :

use File::Spec::Functions qw/catfile/; my $filename = catfile($::folder, $config->{licence});

Thanks

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

Replies are listed 'Best First'.
Re^2: Recover a path from a config file
by GotToBTru (Prior) on Jun 06, 2016 at 18:19 UTC
    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)

      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****