moshefr has asked for the wisdom of the Perl Monks concerning the following question:
I was given the task of accepting a file containing lines which might have one or occurrences of Environment variables defined as ${VAR}. I have to translate within the file all those variables into the environment variable which is defined. My solution was:
Is there an better way?perl -i -n -e ' while ($_ =~ /\${([^\$]*)}/g) { $s = "\\" . $&; $t = $ENV{$+}; s/$s/$t/e; } print $_;' file
20040517 Edit by Corion: Added formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Translating Env Variables
by Abigail-II (Bishop) on May 17, 2004 at 09:04 UTC | |
by Anonymous Monk on May 17, 2004 at 13:47 UTC | |
|
Re: Translating Env Variables
by Anonymous Monk on May 17, 2004 at 10:15 UTC | |
|
Re: Translating Env Variables
by revdiablo (Prior) on May 17, 2004 at 19:25 UTC | |
by dave_the_m (Monsignor) on May 17, 2004 at 21:46 UTC |