In importing the environment from a subcommand, I want to add all environment variables exported from a bash script to a hash. When program
gets run, it will set up some variables and export them. I'd like to save those variables in the Perl script for later. However I don't want to take the bash functions defined in the subcommand. Currently, I have a block like:
foreach (`program; env`)
{
next if /^\(\)/;
my ($a, $b) = split("=", $_);
if( /^(\w+)=(.*)$/ ) {
$hash{$1} = $2;
}
}
Is there a better way to do this? I'm not sure if matching the initial () is safe. Bonus points for handling newlines in environment variables, which I'm just closing my eyes for right now.