If you were to localize them in stead of deleting them
First of all, localizing *them* wouldn't be equivalent. They'd still exist in the hash (with undef for value) rather than not existing at all.
Mind you, you can work around that:
local %ENV = %ENV;
$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
Or in 5.12+:
local $ENV{'PATH'} = '/bin:/usr/bin';
local delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
That said, do you have a reason to restore %ENV? If not, why would you localize it.
|