in reply to Recover a path from a config file

Maybe i didn't ask clear enough my question. I don't want to recover all my config.file. I can do it. I just want to recover path "my $folder" . And add just after licence filename.

I'am doing some tests and i would like to get from my config.file this path using Perl.

And use ,after that, this file to do my tests. Knowing i have to keep my config.file almost identical. For example, i can change "my" to "our" to get a global variable cause it's a very small change.

Global variable seems to be a good approach but i have above issue as i told before.

HTH

Many thanks again !!

*****Lost in translation****TIMTOWTOI****Almost a monk***

Replies are listed 'Best First'.
Re^2: Recover a path from a config file
by Marshall (Canon) on Jun 06, 2016 at 14:29 UTC
    I am confused about this "I can change some stuff, but not much stuff" requirement?

    The code from BrowserUk works fine for me. To eliminate the "only used once" warnings, just declare $folder in main:: as an "our" variable. An "our" variable gets into the global symbol table and can be accessed by anybody with the full name without any import/export adieu. Here is a modified main program...

    #! perl -slw use strict; use Data::Dump qw [ pp ]; our $folder; #to prevent "only used once" warnings our $config; do 'work.conf' or die $!; print $folder; # $folder is declared above, here in $main # not in file work.conf # since we are in main, don't need "full name" pp $::config; #can use full name here, but not necessary
    work.conf as posted by browserUk:
    $::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-30', Marriage_date => '2014-05-26', Divorce_date => '2015-03-30', Activities_folder => $folder.'\VIKTOR\i +ndependent worker', Activities_format => 'Enterprise Format + (V35)', Description_File_from => $folder.'\VIKTOR\F +ILE\description.xlm', ] }, ] };
    works fine. Why isn't this good enough?

    As an update, This back slash stuff for file names under Windows is not required. Use the forward slash. That is easier, more portable and completely allowed since I think at least Win98. The modern Window's command line is NOT DOS.

      Hi Marshall. You right.

      I finally can use a part of browserUk code in mine. A very small part. And i will use a part of haukex code too. I will explain it after.

      *****Lost in translation****TIMTOWTOI****
        From what I can see from your config file, you are using a "BAD idea". In general, I would not use executable Perl code for a simple configuration file because there are standard formats for this, see INI file. There are number of Perl modules that can parse an .INI text file. I would use one of those! I don't see anything that would prevent that?

Re^2: Recover a path from a config file
by haukex (Archbishop) on Jun 06, 2016 at 13:50 UTC

    Hi Chaoui05,

    For example, i can change "my" to "our" to get a global variable cause it's a very small change.

    But earlier you said:

    I meant i have to not modify my config.file. I have to keep it unchanged.

    ... so if you can edit your config file, and if by "above issue" you mean this, then have a look again at my post, I'm guessing you missed the our $folder; in your main script.

    Hope this helps,
    -- Hauke D

      Yes excuse me. I was too much affirmative. Much for me.

      I can do some little changes , which do not lead to a significant impact on config.file structure. I meant.

      In all cases, thanks again haukex. And yes i will review that .

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