develooper Front page | perl.perl5.porters | Postings from May 2015

[perl #125103] Calling each() on an undefined hash returns non-empty list

Thread Next
From:
Huang
Date:
May 5, 2015 12:11
Subject:
[perl #125103] Calling each() on an undefined hash returns non-empty list
Message ID:
rt-4.0.18-20921-1430805547-960.125103-75-0@perl.org
# New Ticket Created by  Huang, Cunzhi 
# Please include the string:  [perl #125103]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=125103 >



Reply-To: cuhuang@akamai.com
Message-Id: <5.20.1_3264_1430699281@AKAMAI>
Subject: Calling each() on an undefined hash returns non-empty list
To: perlbug@perl.org
From: cuhuang@akamai.com


This is a bug report for perl from cuhuang@akamai.com,
generated with the help of perlbug 1.40 running under perl 5.20.1.


-----------------------------------------------------------------
[Please describe your issue here]

Calling each() on an undefined hash returns a non-empty list. The following code
snippet should not print anything, but the print statement was executed twice.

By the way, it is not an issue with Perl 5.18.

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

my %hash;
foreach ( my($k, $v) = each %hash) {
   print "$k, $v\n";
}

#==================================================================
Output:

Use of uninitialized value $k in concatenation (.) or string at each.pl line 6.
Use of uninitialized value $v in concatenation (.) or string at each.pl line 6.
,
Use of uninitialized value $k in concatenation (.) or string at each.pl line 6.
Use of uninitialized value $v in concatenation (.) or string at each.pl line 6.
,



[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=high
---
Site configuration information for perl 5.20.1:

Configured by gecko at Wed Oct 15 14:55:58 2014.

Summary of my perl5 (revision 5 version 20 subversion 1) configuration:

  Platform:
    osname=MSWin32, osvers=6.1, archname=MSWin32-x64-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='C:\Perl64\site\bin\gcc.exe', ccflags =' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields',
    optimize='-s -O2',
    cppflags='-DWIN32'
    ccversion='', gccversion='4.6.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='long long', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='C:\Perl64\site\bin\g++.exe', ldflags ='-s -static-libgcc -static-libstdc++ -L"C:\Perl64\lib\CORE" -L"C:\MinGW\x86_64-w64-mingw32\lib"'
    libpth=C:\MinGW\x86_64-w64-mingw32\lib
    libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    libc=, so=dll, useshrplib=true, libperl=libperl520.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-mdll -s -static-libgcc -static-libstdc++ -L"C:\Perl64\lib\CORE" -L"C:\MinGW\x86_64-w64-mingw32\lib"'

Locally applied patches:
    ActivePerl Build 2000 [298557]

---
@INC for perl 5.20.1:
    C:/Perl64/site/lib
    C:/Perl64/lib
    .

---
Environment for perl 5.20.1:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\ActiveState Komodo Edit 8\;C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Enterprise Vault\EVClient\;C:\Python27;C:\Program Files\Perforce;C:\Program Files (x86)\PuTTY;C:\cygwin64\bin;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\Program Files (x86)\GNU\GnuPG\pub
    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