pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: ilmari@ilmari.org
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: Noah Misch <noah@leadboat.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: libpq environment variables in the server
Date: Fri, 15 Mar 2019 10:06:29 +0000
Message-ID: <d8j4l845u56.fsf@dalvik.ping.uio.no> (raw)
In-Reply-To: <872a3a54-a169-acfc-322a-f6c5b8e89ece@2ndquadrant.com>
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>

Peter Eisentraut <peter.eisentraut@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




view thread (10+ messages)  latest in thread

Message-ID: <d8j4l845u56.fsf@dalvik.ping.uio.no>
Permalink:  ../d8j4l845u56.fsf@dalvik.ping.uio.no/
Also on:    postgresql.org/message-id/d8j4l845u56.fsf@dalvik.ping.uio.no

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: ilmari@ilmari.org, peter.eisentraut@2ndquadrant.com, noah@leadboat.com
  Subject: Re: libpq environment variables in the server
  In-Reply-To: <d8j4l845u56.fsf@dalvik.ping.uio.no>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox