in reply to Recover a path from a config file

Strangely I didn't see this at the beginning of the evening, but after four glasses of wine, I suddenly thought of this and began to wonder why not only me but noone else thought of it yet. I do NOT claim it's subtle coding ;)
open my $ch, 'path to config file'; my $folder; my $assignment = <$ch>; close $ch; chomp $assignment; $assignment =~ s/^\s*my\s*//; eval $assignment; # assigns to THIS scope!

One world, one people

Replies are listed 'Best First'.
Re^2: Recover a path from a config file
by Anonymous Monk on Jun 06, 2016 at 20:35 UTC
      I don't want to get into that example in too much detail as it serves no proper purpose. However, I do have issues with it, for example the local $/ doesn't assign anything so doesn't do anything. Meanwhile I have been thinking what would a proper solution be and I keep getting back to the fact that this is not the best way write a config file. Better would be to have
      { folder => 'path',
      in the following hash, instead of
      my $folder = 'path';
      In any case, unless the config file is used to load all configuration data rather than pick just one item, then it is being misused as well as ill-conceived. There are two types of config file. The language portable one that is just a list of identifiers followed by their values and the "normal" perl way: a class-qualified symbol and a hash assigned to it, which is intended to be loaded in easily enough using just one "require" statement.

      Unfortunately, the OP seems to be suffering from an organisation culture that stubbornly resists change even to fix bad implementations. In the wider Perl community we know who they are by reputation and simply avoid working there!

      One world, one people

        for example the local $/ doesn't assign anything so doesn't do anything.

        local $/; has the effect of setting $/ to undef; thus the subsequent <$fh> reads the entire file. (Slurps it per the comment.)


        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.

        Thanks for the improvements.

        Problem is that i am not allowed to touch config.file.I use this kind of config.file in order to improve my Perl approach.

         unless the config file is used to load all configuration data rather than pick just one item

        Yes, it is the case in part

         In the wider Perl community we know who they are by reputation and simply avoid working there!

        Hope i will be one of this wider community !

        Thanks

        *****Lost in translation****TIMTOWTOI****
      Yes. exact
      *****Lost in translation****TIMTOWTOI****