in reply to Recover a path from a config file

Personally, I would make $folder part of the config structure:

my $folder = 'some/where/else'; { my $folder = 'E:\FOLDER\Test\WEB'; { source_folder => $folder, 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', ] }, ] }; };

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

    Hello Corion. Thanks for reply

    I thought about your approach but i cannot modify my config.file

    So i have to do differently.

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

      Hi Chaoui05,

      i cannot modify my config.file

      With Perl you can ;-)

      There are several other ways to solve this (maybe even PadWalker), and personally I think the following is a hack that's not very nice, but it works as long as your config file only contains one declaration of my $folder...

      my $conf_str = do { open my $fh, '<', 'work.conf' or die $!; local $/; <$fh> }; # slurp ( $conf_str =~ s/\bmy\s*\$folder\b/our \$folder/g )==1 or die q{Failed to match "my $folder" exactly once}; our $folder; my $config = eval $conf_str;

      Hope this helps,
      -- Hauke D

        I meant i have to not modify my config.file. I have to keep it unchanged.
        *****Lost in translation****TIMTOWTOI****

      If you cannot modify the config file, then none of the suggestions here will help. Perhaps you could use eval instead of do?

      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);
      But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

        Hello. Thanks for reply.

        As i told below right now, my issue is to get my path. Because i can read and open my config.file. That is not a problem.

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