kcorcam has asked for the wisdom of the Perl Monks concerning the following question:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: setting perl ENV from file
by Abigail-II (Bishop) on Sep 16, 2003 at 16:10 UTC | |
Abigail | [reply] [d/l] |
Re: setting perl ENV from file
by coreolyn (Parson) on Sep 16, 2003 at 17:19 UTC | |
I'm sure this isn't the cleanest but this is the function I've been using reliably for several years now without a problem against VAR=$VALUE files. In effect I load the vars that will require interpolation into the enviornment, then parse the config file, then add the new values to the environment. The first function function (readDat) just gets the info from another file. The second code snippet (unpackDatArray) does the actual value setting ( including $VARS as long as they are in the environment. ) The third snippet (getEnvValue) substitutes the $VAR for it's value. There are a few functions in these snippets like 'debug' that you'll have to comment out or add similar functionality for them ( i.e. setEnv ).
--------------------
-------------------- coreolyn | [reply] [d/l] [select] |
Re: setting perl ENV from file
by herveus (Prior) on Sep 16, 2003 at 17:56 UTC | |
I faced a similar question in a Korn shell environment. After trying to be tricky and parse the stinker, I realized that the simple approach was superior:
Pass the path to the source file to the sub and it populates %ENV... I use backtick substitution to get the shell to evaluate the profile and dump its environment in a reliable format. C shell would require some modifications to the details, but the basic structure still stands.
yours, | [reply] [d/l] |
by Abigail-II (Bishop) on Sep 17, 2003 at 01:11 UTC | |
Better make that
or else it will break if a value contains a =. Abigail | [reply] [d/l] [select] |
Re: setting perl ENV from file
by kcorcam (Initiate) on Sep 16, 2003 at 16:19 UTC | |
| [reply] |
by halley (Prior) on Sep 16, 2003 at 17:05 UTC | |
This would support an input file with two possible interpolations: It depends on the order of definition. You could iterate the replacement step across all strings until the keys stop changing, but that may raise new problems. -- | [reply] [d/l] [select] |
by flounder99 (Friar) on Sep 16, 2003 at 17:09 UTC | |
-- flounder | [reply] [d/l] |
Re: setting perl ENV from file
by pelagic (Priest) on Jun 08, 2004 at 10:56 UTC | |
pelagic | [reply] [d/l] |