in reply to Re^2: Recover a path from a config file
in thread Recover a path from a config file

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

Replies are listed 'Best First'.
Re^4: Recover a path from a config file
by Chaoui05 (Scribe) on Jun 06, 2016 at 13:12 UTC
    I meant i have to not modify my config.file. I have to keep it unchanged.
    *****Lost in translation****TIMTOWTOI****

      Hi Chaoui05,

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

      The code I showed doesn't modify the config file. It reads the contents of the config file into a Perl string and then modifies that string, leaving the file on disk unchanged.

      Hope this helps,
      -- Hauke D

        Hi haukex,

        With Perl you can ;-)

        I thought you meant i can modify it with Perl.. a misinterpretation.

        I will review that

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