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

Re: setting perl ENV from file

by kcorcam (Initiate)
on Sep 16, 2003 at 16:19 UTC ( [id://291868]=note: print w/replies, xml ) Need Help??


in reply to setting perl ENV from file

Is there anyway to do it from reading and parsing the file?

Replies are listed 'Best First'.
Re: Re: setting perl ENV from file
by halley (Prior) on Sep 16, 2003 at 17:05 UTC
    Assuming you have gotten $key and $value from the file, you could:
    $value =~ s((\$\{(\w+)\}|\$(\w+))) ($ENV{$2} or $ENV{$3} or $1)eg;
    This would support an input file with two possible interpolations:
    key1=value key2=value$key1 key3=${key1}value
    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.

    --
    [ e d @ h a l l e y . c c ]

Re: Re: setting perl ENV from file
by flounder99 (Friar) on Sep 16, 2003 at 17:09 UTC
    This works for simple cases but is not very robust.
    use Data::Dumper; my %envron; while (<DATA>) { chomp; my ($key, $value) = /(.+)=(.*)/; next unless defined $key; $value =~ s/\$(\w+)/$environ{$1}/g; $environ{$key} = $value; } print Data::Dumper->Dump([\%environ], ["*environ"]); __DATA__ myfile=test.log mydir=/kelly/$myfile longdir=/$myfile$mydir __OUTPUT__ %environ = ( 'longdir' => '/test.log/kelly/test.log', 'mydir' => '/kelly/test.log', 'myfile' => 'test.log' );

    --

    flounder

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found