in reply to Retrieving evironment variables from a shell script

Try the following, it doesn't make many assumptions about the conf file.
my $rcfile = 'testrc'; # sets TESTEX to "test!" if(open(CHILD_TO_READ, ". $rcfile; env | sort |")) { while (<CHILD_TO_READ>) { my ($key, $val) = split '='; $ENV{$key} = $val; }; } print $ENV{TESTEX};
Later,
Ray.

Replies are listed 'Best First'.
RE: Re: Retrieving evironment variables from a shell script
by chip (Curate) on Aug 02, 2000 at 10:25 UTC
    Actually, this script makes one unfriendly assumption: That none of the environment variables have values that include newlines.

    How about this, which is also shorter and simpler:

    my $rcfile = 'testrc'; # exports environment vars %CFG = split /\0/, `. $rcfile; $^X -e 'print join("\\0", %ENV)'`;

    (Special var $^X is the patch to the perl binary. And the double backslash is important.)

    If there's any possibility that the config file might do some printing to stdout, you have to get a little more paranoid. Otherwise, this should be fine.

        -- Chip Salzenberg, Free-Floating Agent of Chaos