in reply to Adding a directory to $ENV{PATH}

Any modifications you make to $ENV{PATH} effect the address space of the Unix process that the script is executing in, and not the processes environment. (The environment is kept in kernel memory.)

If you want to add to the and have that honored by system (or backticks or exec()), you'll need to reinvoke the script. In doing so, perl passes $ENV{PATH} to which ever flavor of exec(1) the runtime uses, where it will truly be part of the environment of the nested invocation of your script.

#!/usr/local/bin/perl5
if ( $ARGV[0] eq "child" ) {
    print "child path: $ENV{PATH}\n";
    exit(0);
}
$ENV{PATH} .= ":/dev/null";
print "parent path: $ENV{PATH}\n";
system("/usr/local/bin/perl5", $0, "child");

Replies are listed 'Best First'.
RE: Re: Adding a directory to $ENV{PATH}
by geektron (Curate) on Nov 03, 2000 at 05:02 UTC
    would adding the PATH modification in a BEGIN block fix that issue?
      No, because it merely side-effects the address space of the current Perl process. You need to get the new path into into kernel memory before it will be honored by exec().
        yep. i decided to try and test it, just to satisfy my own curiousity.

        and i got 'no <foo-command> found in . . . .'