develooper Front page | perl.perl5.porters | Postings from January 2014

[perl #120947] Array changes size when accessing past the end using for or grep

Thread Previous
From:
Chris Jack
Date:
January 7, 2014 21:28
Subject:
[perl #120947] Array changes size when accessing past the end using for or grep
Message ID:
rt-4.0.18-3750-1389120031-1411.120947-75-0@perl.org
# New Ticket Created by  Chris Jack 
# Please include the string:  [perl #120947]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=120947 >


This is a bug report for perl from chris_jack@msn.com,generated with the help of perlbug 1.39 running under perl 5.14.4.

-----------------------------------------------------------------[Please describe your issue here]
# The below perl script bug.pl walks through the issue# I get the output:Original length:    2Length is the same: 2Length is more:     4Original length:    2Length is more:     4
when I would expect the output:Original length:    2Length is the same: 2Length is more:     2Original length:    2Length is more:     2
Basically both for and grep seem to extend an array simply by lookingat the contents of elements past the end of the array however thisdoes not happen if I use an element past the end of the array in astraight scalar context.--start bug.pl--# We set up an array of length 2my @array = (1, 2);
# Yes: it really is length 2print "Original length:    " . scalar(@array) . "\n";
# When we access an element past the end as followsunless (defined($array[3])) {}
# Yes: it is still length 2print "Length is the same: " . scalar(@array) . "\n";
# When we access an element past the end using for as followsfor my $a ($array[3]) {}
# Suddenly the length has shot up to 4: is this a bug?print "Length is more:     " . scalar(@array) . "\n";
# Reset the arraymy @array = (1, 2);
# Yes: it is length 2 againprint "Original length:    " . scalar(@array) . "\n";
# When we access an element past the end using grep as followsgrep {defined} ($array[3]);
# Again the length has shot up to 4: is this a bug?print "Length is more:     " . scalar(@array) . "\n";--end bug.pl--

[Please do not change anything below this line]--------------------------------------------------------------------Flags:    category=core    severity=low---Site configuration information for perl 5.14.4:
Configured by Yaakov at Mon Mar 11 18:16:36 CDT 2013.
Summary of my perl5 (revision 5 version 14 subversion 4) configuration:     Platform:    osname=cygwin, osvers=1.7.18(0.26353), archname=cygwin-thread-multi    uname='cygwin_nt-6.1 yaakov04 1.7.18(0.26353) 2013-03-07 19:25 x86_64 cygwin '    config_args='-d -e -Dprefix=/usr -Dmksymlinks -Dusethreads -Darchname=x86_64-cygwin-threads -Dlibperl=cygperl5_14.dll -Dcc=gcc -Dld=g++'    hint=recommended, useposix=true, d_sigaction=define    useithreads=define, usemultiplicity=define    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef    use64bitint=define, use64bitall=define, uselongdouble=undef    usemymalloc=n, bincompat5005=undef  Compiler:    cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -fno-strict-aliasing -pipe -fstack-protector',    optimize='-O3',    cppflags='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -fno-strict-aliasing -pipe -fstack-protector'    ccversion='', gccversion='4.8.0 20130307 (experimental)', gccosandvers=''    intsize=4, longs
 ize=8, ptrsize=8, doublesize=8, byteorder=12345678    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8    alignbytes=8, prototype=define  Linker and Libraries:    ld='g++', ldflags =' -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector'    libpth=/usr/lib /lib    libs=-lgdbm -ldb -ldl -lcrypt -lgdbm_compat    perllibs=-ldl -lcrypt    libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=cygperl5_14.dll    gnulibc_version=''  Dynamic Linking:    dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '    cccdlflags=' ', lddlflags=' --shared  -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector'
Locally applied patches:    Bug#55162 File::Spec::case_tolerant performance    CYG07 $vendorarch/auto/.rebase    CYG15 static Win32CORE    CYG17 cyg-1.7 paths-utf8    0c612ce82 Fix building static extensions on cygwin, -UUSEIMPORTLIB    1bac5ecc1 Fix 64-bit threading sv.c: S_anonymise_cv_maybe    Cygwin::sync_winenv added
---@INC for perl 5.14.4:    /usr/lib/perl5/site_perl/5.14/x86_64-cygwin-threads    /usr/lib/perl5/site_perl/5.14    /usr/lib/perl5/vendor_perl/5.14/x86_64-cygwin-threads    /usr/lib/perl5/vendor_perl/5.14    /usr/lib/perl5/5.14/x86_64-cygwin-threads    /usr/lib/perl5/5.14    .
---Environment for perl 5.14.4:    HOME=/home/cjack    LANG=en_US.UTF-8    LANGUAGE (unset)    LD_LIBRARY_PATH (unset)    LOGDIR (unset)    PATH=/usr/local/bin:/usr/bin:/cygdrive/c/Perl/site/bin:/cygdrive/c/Perl/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files/Intel/WiFi/bin:/cygdrive/c/Program Files/Common Files/Intel/WirelessCommon:/cygdrive/c/Program Files (x86)/Lenovo/Access Connections:/cygdrive/c/Program Files (x86)/Common Files/Ulead Systems/MPEG:/cygdrive/c/Program Files/Lenovo/Hardware Password Manager    PERL_BADLANG (unset)    SHELL=/bin/bash 		 	   		  


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About