develooper Front page | perl.perl5.porters | Postings from April 2000

[ID 20000407.005] Problem with `scalar()' trying to countundefined elements

Thread Next
Janardhan Sridhar
April 7, 2000 11:56
[ID 20000407.005] Problem with `scalar()' trying to countundefined elements
Message ID:

This is a bug report for perl from,
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
  $ 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:
    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=
    cc='cc', optimize='-O', gccversion=
    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/, 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:

Environment for perl 5.004:
    PERL_BADLANG (unset)

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