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

[ID 20010228.002] Bug report: splice/stringification

From:
mgjv
Date:
February 28, 2001 02:16
Subject:
[ID 20010228.002] Bug report: splice/stringification
Message ID:
20010228111504.5BE2.MGJV@tradingpost.com.au
This is a bug report for perl from mgjv@martien.heliotrope.home,
generated with the help of perlbug 1.28 running under perl v5.6.0.


-----------------------------------------------------------------
This problem came to my notice after a discussion on clp.misc about some
problems being reported by Joe Pepin. It was decided that I would file
the bug report, instead of him.

It seems that the return list from splice is influenced by whether or
not the source array's elements have been stringified before the call to
splice. This is even true if the original elements were already strings.
The following program and its output may illustrate what I mean:

#!/usr/local/bin/perl -wl
use strict;
{
	my @a = (1, 2, 3, 4, 5, 6, 7, 8);
	my @foo = @a;
	print join ":", map {$_ || "undef"} splice @a, 0, 4, @a[2,3];
}
{
	my @a = (1, 2, 3, 4, 5, 6, 7, 8);
	my $foo = $_ for @a;
	print join ":", map {$_ || "undef"} splice @a, 0, 4, @a[2,3];
}
{
	my @a = (1, 2, 3, 4, 5, 6, 7, 8);
	my $foo = "@a";
	print join ":", map {$_ || "undef"} splice @a, 0, 4, @a[2,3];
}
{
	my @a = (1, 2, 3, 4, 5, 6, 7, 8);
	my $foo = "$_" for @a;
	print join ":", map {$_ || "undef"} splice @a, 0, 4, @a[2,3];
}
{
	my @a = qw(a b c d e f g);
	my $foo = "$_" for @a;
	print join ":", map {$_ || "undef"} splice @a, 0, 4, @a[2,3];
}
__END__

OUTPUT:
1:2:3:4
1:2:3:4
1:2:undef:undef
1:2:undef:undef
a:b:undef:undef

Changing the order of the blocks makes no difference.

It seems hardly logical to me that the result of these operations should
differ, based on whether the elements of @a had been stringified before
or not, especially if they were already strings.

Martien

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

Configured by mgjv at Sat Mar 25 17:48:49 EST 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.2.12-20, archname=i686-linux
    uname='linux martien 2.2.12-20 #1 mon sep 27 10:40:35 edt 1999 i686
unknown '
    config_args='-des -Dprefix=/opt/perl'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux
(egcs-1.1.2 release)
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=/lib/libc-2.1.2.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.6.0:
    /opt/perl/lib/5.6.0/i686-linux
    /opt/perl/lib/5.6.0
    /opt/perl/lib/site_perl/5.6.0/i686-linux
    /opt/perl/lib/site_perl/5.6.0
    /opt/perl/lib/site_perl/5.005/i686-linux
    /opt/perl/lib/site_perl/5.005
    /opt/perl/lib/site_perl
    .

---
Environment for perl v5.6.0:
    HOME=/home/mgjv
    LANG=en_US
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/opt/3delight-0.6.0/Linux-i686/lib:/opt/pgplot:/opt/post
gresql/lib:/opt/gimp/lib
    LOGDIR (unset)
    PATH=/home/mgjv/bin:/opt/3delight-0.6.0/Linux-i686/bin:/opt/teTeX/bin:/u
sr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/openwin/bin:/
usr/openwin/demo:/opt/samba/bin:/usr/local/ssl/bin:/opt/perl/bin:/opt/ImageM
agick/bin:/opt/java/bin:/opt/mysql/bin:/opt/postgresql/bin:/opt/gimp/bin:/op
t/BMRT/bin:/opt/3delight/Linux-i686/bin:/opt/wordnet/bin
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh





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