Front page | perl.perl5.porters |
Postings from March 2000
[ID 20000308.003] bug in the 'exists' function
From:
Chris Amos
Date:
March 8, 2000 04:32
Subject:
[ID 20000308.003] bug in the 'exists' function
Message ID:
C3408C3AD6D6D211A25F0090272A5D8AFB725D@REIGATEMAIL
Hi
This email has 3 sections:
1. perl version details from 'perl -V'
2. perl program demonstrating the (I think) bug
3. output from the program
Let me know if aI can be of help
Thanks
Chris Amos.
----------------------------------------------------------------------------
-------------------------------------------
Section 1 - Perl version
Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration:
Platform:
osname=dec_osf, osvers=4.0, archname=alpha-dec_osf
uname='osf1 nasaxp.rto.dec.com v4.0 564 alpha '
hint=recommended, useposix=true, d_sigaction=define
bincompat3=y useperlio=undef d_sfio=undef
Compiler:
cc='cc', optimize='-O4', gccversion=
cppflags='-std -D_INTRINSICS -I/usr/local/include -D__LANGUAGE_C__'
ccflags ='-std -D_INTRINSICS -I/usr/local/include -D__LANGUAGE_C__'
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=8, usemymalloc=y, prototype=define
Linker and Libraries:
ld='ld', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /usr/shlib /shlib /lib /usr/lib /usr/ccs/lib
libs=-lgdbm -ldbm -ldb -lm
libc=/usr/shlib/libc.so, so=so
useshrplib=true, libperl=libperl.so
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='
-Wl,-rpath,/usr/opt/PERL5004/lib/perl5/alpha-dec_osf/5.00404/CORE'
cccdlflags=' ', lddlflags='-shared -expect_unresolved "*" -O4 -msym -s
-L/usr/local/lib'
Characteristics of this binary (from libperl):
Built under dec_osf
Compiled at Nov 7 1997 20:19:49
@INC:
/usr/opt/PERL5004/lib/perl5/alpha-dec_osf/5.00404
/usr/opt/PERL5004/lib/perl5
/usr/opt/PERL5004/lib/perl5/site_perl/alpha-dec_osf
/usr/opt/PERL5004/lib/perl5/site_perl
.
----------------------------------------------------------------------------
------------------------------------------------------------
Section 2 - the program
$h{key1_x}{key2_x} = 'I exist';
#
# Does the element we created exist?
#
print "Test 1 - 2D hash element we know exists\n";
if (exists $h{key1_x}{key2_x})
{
#
# The hash element exists - that's what we expected
#
print "Hoorahh! he exists: '$h{key1_x}{key2_x}'\n";
}
else
{
#
# The hash element doesn't exist - that's bad
#
print "Uh oh, he's gone awol\n";
}
#################################################################
#
# Change key 1 and key2 of the hash - does it exist?
#
print "Test 2 - 2D hash element we know doesn't exists (new key1 and
key2)\n";
if (exists $h{key1_y}{key2_y})
{
#
# The hash element exists - that's bad
#
print "Uh oh, he does exist: $h{key1_y}{key2_y}\n";
}
else
{
#
# The hash element doesn't exist - that's what we expected
#
print "Hoorahh! he doesn't exist\n";
}
#################################################################
print "Test 3 - Does key1 of the 2D hash exist (same key1 as test 2)?\n";
#
# Use key1 from test 2 - it shouldn't exist.
#
if (exists $h{key1_y})
{
#
# The hash element exists - that's bad
#
print "Uh oh, he does exist: $h{key1_y}\n";
}
else
{
#
# The hash element doesn't exist - that's what we expected
#
print "Hoorahh! he doesn't exist\n";
}
----------------------------------------------------------------------------
--------------------------------------------------
Section 3 - The program output
Test 1 - 2D hash element we know exists
Hoorahh! he exists: 'I exist'
Test 2 - 2D hash element we know doesn't exists (new key1 and key2)
Hoorahh! he doesn't exist
Test 3 - Does key1 of the 2D hash exist (same key1 as test 2)?
Uh oh, he does exist: HASH(0x14000b718)
----------------------------------------------------------------------------
------------------------------------------------------
-
[ID 20000308.003] bug in the 'exists' function
by Chris Amos