in reply to Re: Retrieving evironment variables from a shell script
in thread Retrieving evironment variables from a shell script

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