Peter Eisentraut <peter.eisentr...@2ndquadrant.com> writes: > On 2019-03-15 05:00, Noah Misch wrote: >> I consider the following style more idiomatic: >> >> { >> local %ENV; >> delete $ENV{PGAPPNAME}; >> ... >> } > > That doesn't work because the first line clears the entire environment.
The solution to that is to do 'local %ENV = %ENV;', to assign a copy of the original to the localised variable. This doesn't work on VMS, because its concept of environment variables is quite different from UNIX, but PostgreSQL doesn't support that anyway. > What does work is > > { > delete local $ENV{PGAPPNAME}; > ... > } > > But that is documented as new in Perl 5.12.0, so we might not be able to > use it. It appears to work in the 5.8.9 I have lying around, so I'm > confused. It "works" as in it's not a syntax error, but it doesn't actually localise the deletion. The following program: use strict; use warnings; use feature 'say'; our %env = qw(foo bar baz bat); say "original: ", join(", ", sort keys %env); { delete local $env{foo}; say "localised: ", join(", ", sort keys %env); } say "restored? ", join(", ", sort keys %env); on 5.12 prints: original: baz, foo localised: baz restored? baz, foo while on 5.10 it prints: original: baz, foo localised: baz restored? baz BTW, https://perl.bot/ is handy for testing things like this on various Perl versions you don't have lying around. - ilmari -- - Twitter seems more influential [than blogs] in the 'gets reported in the mainstream press' sense at least. - Matt McLeod - That'd be because the content of a tweet is easier to condense down to a mainstream media article. - Calle Dybedahl