in reply to Recover a path from a config file

If you create the variable in the config as $::folder = 'E:\FOLDER\Test\WEB';, then it is available in the main program in the same way.

However, the bulk of the config will be inaccessible as it is declared as an anonymous hash with no name.

You could fix that with work.conf:

$::folder = 'E:\FOLDER\Test\WEB'; $::config = { license => 'kit-licence.zip', programs => [ #template society =>\%program_work 'VIKTOR DESCRIPTION PRODUCT' => { name => 'VIKTOR ', parameters => [ Count_id => '06 ( +Viktor)', Birth_date => '1995-04-3 +0', Marriage_date => '2014-05-26', Divorce_date => '2015-03-30', Activities_folder => $folder. +'\VIKTOR\independent worker', Activities_format => 'Enterpr +ise Format (V35)', Description_File_from => $folder.'\VI +KTOR\FILE\description.xlm', ] }, ] };

Main program:

#! perl -slw use strict; use Data::Dump qw [ pp ]; do 'work.conf' or die $!; print $::folder; pp $::config;

Output:

C:\test>junk Name "main::folder" used only once: possible typo at C:\test\junk.pl l +ine 7. Name "main::config" used only once: possible typo at C:\test\junk.pl l +ine 9. E:\FOLDER\Test\WEB { license => "kit-licence.zip", programs => [ "VIKTOR DESCRIPTION PRODUCT", { name => "VIKTOR ", parameters => [ "Count_id", "06 (Viktor)", "Birth_date", 1995-04-30, "Marriage_date", 2014-05-26, "Divorce_date", 2015-03-30, "Activities_folder", "E:\\FOLDER\\Test\\WEB\\VIKTOR\\independent wo +rker", "Activities_format", "Enterprise Format (V35)", "Description_File_from", "E:\\FOLDER\\Test\\WEB\\VIKTOR\\FILE\\descript +ion.xlm", ], }, ], }

Also $main::config & $main::folder would work. Or you could go the OO route and make work.conf a proper object.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.

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

    Hello . Thanks for reply.

    In fact, i just want to get my path + filename in my test.pl using perl, knowing i have to keep my config.file unchanged.

    Thanks in advance !

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