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

[ID 20010712.005] Perl bug with "delete" on arrays

Thread Next
Andrew C. Ryan
July 12, 2001 13:13
[ID 20010712.005] Perl bug with "delete" on arrays
Message ID:

This is a bug report for perl from,
generated with the help of perlbug 1.28 running under perl v5.6.0.

[Please enter your report here]


According to the man page on and the description given in Programming Perl, 3rd edtion, for Perl's delete() function, "delete $a[$#a];" 
should be equivalent to "$#a--".  But it looks like the delete, when used on the last elements of arrays, has a bug, because at the end of program, 
when the garbage collector is cleaned up befow exiting, it gives a "Attempt to free unreferenced scalar." error for each time a statement like "delete 
$a[$#a];" is executed.  Below, I give the PERL version and a couple of one-line programs to illustrate the bug.

-- Andrew

$ perl -v

This is perl, v5.6.0 built for sun4-solaris

Copyright 1987-2000, 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.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at, the Perl Home Page.

$ perl -e 'use strict; my @a = (1, 2, 3); $#a--; $a[4] = 5; print "@a\n";'
1 2   5
$ perl -e 'use strict; my @a = (1, 2, 3); delete $a[$#a]; $a[4] = 5; print "@a\n";'
1 2 5  5
Attempt to free unreferenced scalar.

[Please do not change anything below this line]
Site configuration information for perl v5.6.0:

Configured by nhogan at Wed Jun  7 14:51:45 CDT 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
    osname=solaris, osvers=2.8, archname=sun4-solaris
    uname='sunos einstein 5.8 generic sun4u sparc sunw,ultra-enterprise '
    config_args='-Accflags=-DPERL_POLLUTE -Uusedl -Dcc=gcc -Dprefix=/celox'
    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
    cc='gcc', optimize='-O', gccversion=2.8.1
    cppflags='-DPERL_POLLUTE -I/usr/local/include'
    ccflags ='-DPERL_POLLUTE -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=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='ld', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -lgdbm -ldl -lm -lc -lcrypt -lsec
    libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_none.xs, dlext=none, d_dlsymun=undef, ccdlflags=''
    cccdlflags='', lddlflags=''

Locally applied patches:

@INC for perl v5.6.0:

Environment for perl v5.6.0:
    LANG (unset)
    LANGUAGE (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

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