in reply to Recover a path from a config file

Hi Chaoui05,

Because the $folder variable is declared with my, it exists only for the scope of the config file and is not accessible from the main script. One quick solution would be to replace the "my" with an "our" in the config file, as that declares the variable as a package ("global") variable, then add a declaration of "our $folder;" (or "use vars qw/$folder/;", but that's discouraged) before the line with do 'work.conf' (this is to satisfy strict), then the variable $folder will be accessible in the script, and then you can do:

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

Hope this helps,
-- Hauke D

Edit: Minor updates to wording.

Replies are listed 'Best First'.
Re^2: Recover a path from a config file
by Chaoui05 (Scribe) on Jun 06, 2016 at 11:32 UTC

    Hey haukex . Thanks for reply.

    Global variable is a good idea ! I tried it but i get an issue. Here my output :
    Global symbol "$folder" requires explicit package name at...line44

    Thanks in advance !

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