Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: setting perl ENV from file

by herveus (Prior)
on Sep 16, 2003 at 17:56 UTC ( [id://291902]=note: print w/replies, xml ) Need Help??


in reply to setting perl ENV from file

Howdy!

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:

sub profile { my $self = shift; my $profile = shift; foreach (`. $profile; env`) { chomp; next unless /=/; my ($var, $value) = split(/=/, $_); $ENV{$var} = $value; } }

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,
Michael

Replies are listed 'Best First'.
Re: setting perl ENV from file
by Abigail-II (Bishop) on Sep 17, 2003 at 01:11 UTC
    my ($var, $value) = split(/=/, $_);

    Better make that

    my ($var, $value) = split(/=/, $_, 2);

    or else it will break if a value contains a =.

    Abigail

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 09:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found