develooper Front page | perl.perl5.porters | Postings from December 2012

Undocumented %ENV behaviour.

Thread Next
Kent Fredric
December 15, 2012 03:10
Undocumented %ENV behaviour.
Message ID:
While trying to track down a bug on Dancer w/ 5.17.6, I managed to find a
quirk in %ENV thats not documented where I'd expect it to be ( perldoc
perlvar beside %ENV ).

The only relevant documentation I can find is :

It says "A value stored in an environment variable has always been

However, testing this myself with a sample perl script on 5.16.2 shows this
is not the case:


use strict;
use warnings;

my %hash;
    my $content = "hello";
    open my $fh, '<', \$content;
    $ENV{'foo'} = $fh;
    $hash{'foo'} = $fh;

print "ENV{'foo'} is " . ( ref $ENV{'foo'} ? '' :  'not ') . "a ref\n";
print "hash{'foo'} is " . ( ref $hash{'foo'} ? '' : 'not ') . "a ref\n";


5.16.2 , %ENV and %hash behave the same,
5.17.6,  %ENV stringifies values.

So 3 changes really need to happen here IMO,

1: Document the stringification closer to  `perldoc perlvar %ENV`
2: Make the documentation about this change in perldelta clearer ( its not
obvious that stringification is a new change )
3: Optional: Create a warnings class for inserting refs into %ENV that get

As it is, Dancer appears to have a fair amount of code dependent on ENV
being able to store references, and it took a while to track down the bug
caused by the behaviour change.

Stringification of a value may be expected behaviour when you use a hash
key, but stringification when storing as a *value* is certainly surprising,
and really aught to be noisier.


perl -e  "print substr( \"edrgmaM  SPA NOcomil.ic\\@tfrken\", \$_ * 3, 3 )
for ( 9,8,0,7,1,6,5,4,3,2 );"

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About