Front page | perl.perl5.porters |
Postings from April 2000
[ID 20000407.005] Problem with `scalar()' trying to countundefined elements
Thread Next
From:
Janardhan Sridhar
Date:
April 7, 2000 11:56
Subject:
[ID 20000407.005] Problem with `scalar()' trying to countundefined elements
Message ID:
200004071855.OAA19241@sisgate.superiorinfo.com
This is a bug report for perl from sridhar@cji.com,
generated with the help of perlbug 1.17 running under perl 5.004.
-----------------------------------------------------------------
[Please enter your report here]
Following is an account of what could be a bug in perl.
$ perl -e 'print "count is ", scalar(undef, undef), "\n"'
count is
Note that count is undefined here, though it should have been 2.
OK, assuming undef's are not counted, then the following should
not work too.
$ perl -e '@c = (undef, undef); print "count is ", scalar(@c), "\n"'
count is 2
But that works fine.
Is it because `scalar()' cannot count lists, but only arrays? Doesn't
sound right, so let's check it out.
$ perl -e 'print "count is ", scalar(1, 2, 3), "\n"'
count is 3
So scalar() can count lists, so that's not true either.
Here are more variations of the same.
$ perl -e 'print "count is ", scalar(1, undef), "\n"'
count is
Here though there is a valid value in the list, `scalar()' breaks.
But the following does count the elements though it arrives at a wrong
answer.
$ perl -e 'print "count is ", scalar(1, 2, undef, 3), "\n"'
count is 3
And the following doesn't count at all.
$ perl -e 'print "count is ", scalar(1, 2, 3, undef), "\n"'
count is
Apparently the presence of an `undef' at the end of the list seems to
be causing problems.
And finally this is the version info of perl
$ perl -v
This is perl, version 5.004
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Site configuration information for perl 5.004:
Configured by gan at Fri Aug 29 10:52:11 EDT 1997.
Summary of my perl5 (5.0 patchlevel 4 subversion 0) configuration:
Platform:
osname=solaris, osvers=2.5.1, archname=sun4-solaris
uname='sunos sisgate 5.5.1 generic_103640-08 sun4u sparc sunw,ultra-2 '
hint=recommended, useposix=true, d_sigaction=define
bincompat3=y useperlio= d_sfio=
Compiler:
cc='cc', optimize='-O', gccversion=
cppflags=''
ccflags =''
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=8, usemymalloc=y, randbits=15
Linker and Libraries:
ld='cc', ldflags =''
libpth=/lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -ldl -lm -lc -lcrypt
libc=/lib/libc.so, so=so
useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags=' '
cccdlflags='-Kpic', lddlflags='-G'
---
@INC for perl 5.004:
/export/home/perl5/sun4-solaris/5.004
/export/home/perl5
/export/home/perl5/site_perl/sun4-solaris
/export/home/perl5/site_perl
.
---
Environment for perl 5.004:
PATH=/usr/bin:/bin:/usr/lbin:/usr/sbin:/usr/ccs/bin:/raid/cvs/bin:/usr/openwin/bin:/export/home/perl5/bin:/usr/local/bin:/raid/gnu/bin:/raid/misc/bin:/opt/SUNWspro/SC4.2/bin:/export/home/sridhar/local/bin::/raid/oracle/u01/app/oracle/product/8.0.5/bin:/raid/oracle/u01/app/oracle/product/8.0.5/bin:/raid/oracle/u01/app/oracle/product/8.0.5/bin
LD_LIBRARY_PATH=/export/home/sridhar/local/lib
PERL_BADLANG (unset)
Thread Next
-
[ID 20000407.005] Problem with `scalar()' trying to countundefined elements
by Janardhan Sridhar