Front page | perl.perl5.porters |
Postings from February 2001
[ID 20010220.003] Totally unclear behaviour in the looking good code
Thread Next
From:
alex
Date:
February 20, 2001 07:26
Subject:
[ID 20010220.003] Totally unclear behaviour in the looking good code
Message ID:
200102201525.f1KFPZ807336@sig.novosoft.ru
This is a bug report for perl from morozov@novosoft.ru,
generated with the help of perlbug 1.28 running under perl v5.6.0.
-----------------------------------------------------------------
[Please enter your report here]
Consider the following code:
-------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use diagnostics;
sub bad_func
{
my ($key) = @_;
my %hash = (
'key1' => 'value1',
'key2' => 'value2',
);
return unless $hash{$key};
return $hash{$key};
}
sub value1 { return bad_func('key1'); }
sub value2 { return bad_func('key2'); }
sub value3 { return bad_func('key3'); }
sub value4 { my $r = bad_func('key4'); return $r; }
testfunc('key1',value1(),'key2',value2(),'key3',value3(),'key4',value4());
sub testfunc
{
foreach my $elem (@_)
{
print "Got ".((defined $elem) ? "'$elem'" : 'undef')."\n";
}
}
-------------------------------------------------------
It produces the following:
Got 'key1'
Got 'value1'
Got 'key2'
Got 'value2'
Got 'key3'
Got 'key4'
Got undef
------------------------------------------------------
Just wonder why I got NO VALUE AT ALL even undef for value3() call.
As you probably guessed I passed to the testfunc a hash initially and got
a totally insane result. You'll be probably interested that bad_func
was initially CGI->param() (w/ properly constructed CGI object of course).
So we have a completely unclear behaviour in so simple and clear looking
code. I'm totally disappointed.
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=medium
---
Site configuration information for perl v5.6.0:
Configured by alex at Mon Oct 30 12:23:03 NOVT 2000.
Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
Platform:
osname=linux, osvers=2.4.0-test9, archname=i386-linux
uname='linux sig.novosoft.ru 2.4.0-test9 #2 ÷ÓË ïËÔ 29 22:59:33 novt 2000 i686 unknown '
config_args='-des -Darchname=i386-linux -Dd_dosuid -Dd_semctl_semun -Di_db -Di_ndbm -Di_gdbm -Duseperlio -Dusesocks -Duselargefiles -Dprefix=/usr -Dinstallprefix=/usr -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/perl5/man/man3 -Dprivlib=/usr/share/perl5 -Dsitelib=/usr/local/share/perl5 -Darchlib=/usr//lib/perl-5.6.0 -Dsitearch=/usr/local/lib/perl-5.6.0 -Dlibperl=libperl.so.5.6.0 -Duseshrplib=true -Doptimize=-O2 -march=pentiumpro -mcpu=pentiumpro -pipe'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define
use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=define
Compiler:
cc='cc', optimize='-O2 -march=pentiumpro -mcpu=pentiumpro -pipe', gccversion=2.96 20000731 (Red Hat Linux 7.0)
cppflags='-DSOCKS -fno-strict-aliasing'
ccflags ='-DSOCKS -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
stdchar='char', d_stdstdio=define, usevfork=false
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lc -lcrypt -lsocks5 -lsocks5_sh
libc=/lib/libc-2.1.94.so, so=so, useshrplib=true, libperl=libperl.so.5.6.0
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr//lib/perl-5.6.0/CORE'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Locally applied patches:
---
@INC for perl v5.6.0:
/usr//lib/perl-5.6.0
/usr/share/perl5
/usr/local/lib/perl-5.6.0
/usr/local/share/perl5
/usr/local/share/perl5
.
---
Environment for perl v5.6.0:
HOME=/home/alex
LANG=ru_RU.KOI8-R
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/bin:/usr/bin:/usr/bin/X11:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/home/alex/bin:/home/alex/bin:/home/alex/bin:/home/alex/bin:/home/alex/bin
PERL_BADLANG (unset)
SHELL=/bin/bash
Thread Next
-
[ID 20010220.003] Totally unclear behaviour in the looking good code
by alex