develooper Front page | perl.perl5.porters | Postings from November 2003

[perl #24515] [no subject]

Thread Next
November 18, 2003 19:54
[perl #24515] [no subject]
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #24515]
# in the subject line of all future correspondence about this issue. 
# <URL: >

Subject: HoH and HoA strange behaviour
Reply-To: (Ivan Fomichev)
Message-Id: <>

This is a bug report for perl from,
generated with the help of perlbug 1.34 running under perl v5.8.0.

[Please enter your report here]

I discovered that when one refers a hash or an array element of
a non-existent hash element in HoH or HoA correspondingly, Perl
creates this element for no particular reason. IMHO.

There are two simple tests.

#!/usr/bin/perl -w
use strict;
use Data::Dumper;

my %HoA = ( vodka => [ 40, 0.5 ], beer => [ 5, 0.33 ] );
print '$HoA{cognac} ', exists $HoA{cognac} ? 'exists' : 'not exists', "\n";
$_ = $HoA{cognac}[0]; # affect $HoA{cognac}
print '$_ is ', defined $_ ? 'defined' : 'undefined', "\n";
print 'Now $HoA{cognac} ', exists $HoA{cognac} ? 'exists' : 'not exists', "\n"; 

print "\n%HoA contains: \n", Dumper(\%HoA);
#!/usr/bin/perl -w
use strict;
use Data::Dumper;

my %HoH = ( vodka => { spirits => 40, volume => 0.5 },
            beer  => { spirits => 5,  volume => 0.33 } );
print '$HoH{cognac} ', exists $HoH{cognac} ? 'exists' : 'not exists', "\n";
$_ = $HoH{cognac}{color}; # affect $HoH{cognac}
print '$_ is ', defined $_ ? 'defined' : 'undefined', "\n";
print 'Now $HoH{cognac} ', exists $HoH{cognac} ? 'exists' : 'not exists', "\n";

print "\n%HoH contains: \n", Dumper(\%HoH);

I don't mind by no means that Perl silently assigns 'undef' when I refer to
that non-existent element, but why on Earth it pokes its nose into my
hash? (Sorry if I've gone mad, I did not mind any offence :-)

If you would so kind, I would know your opinion on such disgraceful
behaviour of Perl.

Best regards, Ivan Fomichev.

[Please do not change anything below this line]
Site configuration information for perl v5.8.0:

Configured by root at Mon Mar 24 21:18:49 MST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
    osname=openbsd, osvers=3.3, archname=sparc64-openbsd
    config_args='-Dopenbsd_distribution=defined -dsE'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=define uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include',
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.3 20010125 (prerelease, propolice)', gccosandvers='openbsd3.3'
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=87654321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-Wl,-E '
    libs=-lm -lc -lutil
    perllibs=-lm -lc -lutil
    libc=/usr/lib/, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-R/usr/libdata/perl5/sparc64-openbsd/5.8.0/CORE'
    cccdlflags='-DPIC -fPIC ', lddlflags='-shared -fPIC '

Locally applied patches:

@INC for perl v5.8.0:

Environment for perl v5.8.0:
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

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