Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Replacing environment variables

by holli (Abbot)
on Oct 18, 2006 at 12:54 UTC ( [id://579061]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Replacing environment variables
in thread Replacing environment variables

while (<DATA>) { # match any dollar followed by a number # of non whitespaces (unicode safe) # and replace it by then corresponding # environment variable if ( s/\$(\P{IsSpace}+)/$ENV{$1}/ ) { $undefinedVars++ unless $ENV{$1}; } print; } if ( $undefinedVars > 0) { print "\n\nERROR: There were $undefinedVars undefined variables!\n +"; } __DATA__ bigcompany.product.part.path=$PATH bigcompany.product.part.widgit=$WIDGIT bigcompany.product.part.battery=$BATTERY bigcompany.product.part.frobnicator=$FROBNICATOR


holli, /regexed monk/

Replies are listed 'Best First'.
Re^4: Replacing environment variables
by loris (Hermit) on Oct 18, 2006 at 14:03 UTC

    Thanks for the nice concise solution, holli. Looking at it, I realise that I have missed out the case where the environment variable represents a directory and may be followed by a subdirectory (see updated OP). Thus the regexp would have to be a little different.

    loris


    "It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://579061]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-24 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found