On Tue, Feb 8, 2011 at 9:25 AM, Yossi Itzkovich
<[email protected]> wrote:
> Hi,
>
> In one of my scripts I have to launch an external utility, and since it might
> not be in the user path, I would like to add the target directory (or
> directories) to the PATH environment. To be on the safe side, I want to
> restore the original path after execution of the utility.
> I thought of using:
>
> {
> local $ENV{PATH}.=":/new/path/to/use";
> `externalUtility`;
> }
>
> The problem is that I want to do ".=", but at this point (because of
> "local"), the original value is empty.
> Is there a trick here to use, or should I do it by saving the old path,
> setting the new one, restore the old value ?
You can use this:
{
local $ENV{PATH} = $ENV{PATH} . ':' . '/new/path/to/use';
print $ENV{PATH};
}
but it is probably better to take the separator character from the configuration
of Perl as it is not ':' on all the operating systems.
use Config;
{
local $ENV{PATH} = $ENV{PATH} . $Config{path_sep} . '/new/path/to/use';
print $ENV{PATH};
}
Of course then the path should also look different but let me not fix that now
Gabor
http://szabgab.com/
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl