develooper Front page | perl.perl5.porters | Postings from August 2001

[ID 20010810.008] exists($_[0]) fails for @_ = (undef) in sub calls

Thread Next
From:
Michael Carman
Date:
August 10, 2001 13:38
Subject:
[ID 20010810.008] exists($_[0]) fails for @_ = (undef) in sub calls
Message ID:
3B7445FA.203CBF01@home.com
This is a bug report for perl from mjcarman@home.com,
generated with the help of perlbug 1.28 running under perl v5.6.0.

-----------------------------------------------------------------
Consider the following code:

#!/usr/local/bin/perl -w
use strict;

foo('A', undef, 'B');

sub foo {
    foreach my $i (0 .. $#_) {
        printf("$i: %6s %7s\n",
            exists  $_[$i] ? 'exists'  : '',
            defined $_[$i] ? 'defined' : '',
        );
    }
}

I would expect this to print

0: exists defined
1: exists
2: exists defined

Instead it prints

0: exists defined
1:               
2: exists defined

The second line is obviously incorrect. How can we iterate 
over an array element that doesn't exist? I don't believe that
this is a bug in exists(), because

perl -e "@_ = (undef); print qq(exists\n) if exists $_[0]"

prints 'exists' as expected.

No patch -- I don't know the internals, but there seems to be 
something special in how @_ is populated for subroutine calls
that prevents exists() from working properly.

I observed the same problem in perl v5.6.1 for sun4-solaris.

-mjc


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl v5.6.0:

Configured by mjcarman at Tue Oct 31 18:30:54 2000.

Summary of my perl5 (revision 5 version 6 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=undef d_sfio=undef uselargefiles=undef 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cl', optimize='-O1 -MD -DNDEBUG', gccversion=
    cppflags='-DWIN32'
    ccflags ='-O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release  -libpath:"D:\Perl\lib\CORE"  -machine:x86'
    libpth="D:\Perl\lib\CORE"
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib
winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release  -libpath:"D:\Perl\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY

---
@INC for perl v5.6.0:
    d:\perl\perlman\lib
    D:/Perl/lib
    D:/Perl/site/lib
    .

---
Environment for perl v5.6.0:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=D:\Perl\bin\;D:\Rational\Apex_Ada\releases\apex.3.0.2b\nt_x86\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\WBEM;D:\Program Files\Rational
Software\ClearCase\bin;D:\Rational\Apex_Ada\releases\apex.3.0.2b\nt_x86\mstools\bin;D:\Program Files\Rational\common;s:\o;d:\ppt;d:\perl\perlman\bin
    PERL5LIB=d:\perl\perlman\lib
    PERL_BADLANG (unset)
    SHELL (unset)


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