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

[perl #24515] [no subject]

Thread Next
From:
perlbug-followup
Date:
November 18, 2003 19:54
Subject:
[perl #24515] [no subject]
Message ID:
rt-24515-67592.10.6787239577132@rt.perl.org
# New Ticket Created by  johnny@ersatz.org 
# Please include the string:  [perl #24515]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24515 >


To: perlbug@perl.org
Subject: HoH and HoA strange behaviour
Reply-To: johnny@net.frn.ru (Ivan Fomichev)
Message-Id: <5.8.0_21793_1069159085@rotfront.ersatz.org>

This is a bug report for perl from johnny@net.frn.ru,
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]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
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:
  Platform:
    osname=openbsd, osvers=3.3, archname=sparc64-openbsd
    uname='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
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include',
    optimize='-O2',
    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 '
    libpth=/usr/lib
    libs=-lm -lc -lutil
    perllibs=-lm -lc -lutil
    libc=/usr/lib/libc.so.29.0, so=so, useshrplib=true, libperl=libperl.so.8.0
    gnulibc_version=''
  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:
    /usr/libdata/perl5/sparc64-openbsd/5.8.0
    /usr/local/libdata/perl5/sparc64-openbsd/5.8.0
    /usr/libdata/perl5
    /usr/local/libdata/perl5
    /usr/local/libdata/perl5/site_perl/sparc64-openbsd
    /usr/libdata/perl5/site_perl/sparc64-openbsd
    /usr/local/libdata/perl5/site_perl
    /usr/libdata/perl5/site_perl
    /usr/local/lib/perl5/site_perl
    .

---
Environment for perl v5.8.0:
    HOME=/home/johnny
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/bin:/usr/X11R6/bin:/home/johnny/bin
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/bash


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