In my Perl script, I'm trying to set an environment variable (for example PATH). In case it's already defined, add the path to it. Otherwise, set the env. The code:
if (defined($ENV{"PATH"})) {
$ENV{"PATH"} = $ENV{"PATH"}.":/usr/pkgs/";
} else {
$ENV{"PATH"} = "/usr/pkgs/";
}
Is there a better and elegant way to do this in Perl? Maybe a one liner? Note that the env does not have to be PATH.