Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h4jjb-0001ee-87 for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Mar 2019 10:06:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h4jjZ-0001w6-Qf for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Mar 2019 10:06:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h4jjZ-0001vy-JH for pgsql-hackers@lists.postgresql.org; Fri, 15 Mar 2019 10:06:37 +0000 Received: from ping.uio.no ([2001:700:100:570::196]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h4jjW-0003qK-PO for pgsql-hackers@postgresql.org; Fri, 15 Mar 2019 10:06:36 +0000 Received: from [2001:700:100:570::211] (helo=dalvik.ping.uio.no ident=Debian-exim) by ping.uio.no with esmtp (Exim 4.72 #1 (Debian)) id 1h4jjR-0007kX-JT; Fri, 15 Mar 2019 11:06:30 +0100 Received: from ilmari by dalvik.ping.uio.no with local (Exim 4.84_2) (envelope-from ) id 1h4jjR-0001Lu-DF; Fri, 15 Mar 2019 11:06:29 +0100 From: ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) To: Peter Eisentraut Cc: Noah Misch , pgsql-hackers Subject: Re: libpq environment variables in the server References: <33383613-690e-6f1b-d5ba-4957ff40f6ce@2ndquadrant.com> <744962da-c27f-c992-4058-364463857ee0@2ndquadrant.com> <20190303080620.GA1750246@rfd.leadboat.com> <35af0500-5eea-d2f0-339e-07a457a5f6bc@2ndquadrant.com> <20190315040053.GB2607362@rfd.leadboat.com> <872a3a54-a169-acfc-322a-f6c5b8e89ece@2ndquadrant.com> Mail-Copies-To: nobody Date: Fri, 15 Mar 2019 10:06:29 +0000 In-Reply-To: <872a3a54-a169-acfc-322a-f6c5b8e89ece@2ndquadrant.com> (Peter Eisentraut's message of "Fri, 15 Mar 2019 09:15:24 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Exiscan-Spam-Score: -3.7 (---) X-Exiscan-Spam-Report: SpamAssassin 3.3.1 (2010-03-16) on pike.ping.uio.no Score Rule * -5.0 PING_UIO_MAIL_IS_INTERNAL Message has never been outside * 129.240.0.0/16 or 193.157.115.0/24 * 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Eisentraut 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