develooper Front page | perl.perl5.porters | Postings from February 2013

Re: [perl #114504] $ENV{foo}=undef

Thread Previous | Thread Next
From:
Craig A. Berry
Date:
February 23, 2013 17:56
Subject:
Re: [perl #114504] $ENV{foo}=undef
Message ID:
CA+vYcVzMMmSpOtiQBDTWsULwq99X2_5nogLjSpcAc91LLsFueA@mail.gmail.com
On Sat, Feb 16, 2013 at 12:46 PM, Kent Fredric via RT
<perlbug-comment@perl.org> wrote:
> Just regenerated the patch with a cleanup of the ENV variable I added for
> my test. I didn't see that the first time around. VMS is *weird*

If you're referring to the snippets of eccentricity in mg.c and hv.c,
that's only the tip of the iceberg; the darker magic is in vms/vms.c.

I'm actually not sure what to do about this change on VMS.
t/op/magic.t now fails like so:

ok 157 - setting $0 does not break %ENV
not ok 158 - setting a key as undef does not delete it
# Failed test 158 - setting a key as undef does not delete it at
op/magic.t line 69
#      got "\000\n"
# expected "\n"
ok 159 - ENV store of stringified glob

What's happening here is that when we set an environment variable to
undef, we're actually storing a null byte as the value in the "real"
(external to Perl) environment.  This is necessary because storing
zero-length values is not allowed.  It's possible because the native
interfaces do not use C (ASCIZ) strings but always specify string
lengths on input and output.

When we retrieve such a value from Perl, we correctly recognize that
the value exists but is undefined:

$ perl -e "$ENV{XYZ}='foo'; $ENV{XYZ}=undef; print qq/exists but
undef\n/ if exists $ENV{XYZ} && !defined $ENV{XYZ};"
exists but undef

but the env_is() subroutine in magic.t is retrieving that null byte by
running an external command.  I guess I will just hack up env_is() to
handle this special case.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About