develooper Front page | perl.perl5.porters | Postings from October 2005

Re: [perl #37350] $#{@$aref} in debugger gives: Bizarre copy of ARRAYin leave

From:
David Landgren
Date:
October 11, 2005 10:18
Subject:
Re: [perl #37350] $#{@$aref} in debugger gives: Bizarre copy of ARRAYin leave
Message ID:
434BF3DB.6080705@landgren.net
lallip@cs.rpi.edu (via RT) wrote:
> # New Ticket Created by  lallip@cs.rpi.edu 
> # Please include the string:  [perl #37350]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=37350 >
> 
> 
> This transaction appears to have no content
> 
> 
> ------------------------------------------------------------------------
> 
> To: perlbug@perl.org
> Subject: $#{@$aref} in debugger gives: Bizarre copy of ARRAY in leave
> Reply-To: lallip@cs.rpi.edu
> 
> This is a bug report for perl from lallip@cs.rpi.edu,
> generated with the help of perlbug 1.33 running under perl v5.6.1.
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> An example program:
> #!/usr/bin/perl -d
> use strict;
> use warnings;
> 
> my $i;
> my $aref = [1..10];
> for ($i=0; $i<=$#{@$aref}; $i++){
>     print "$i: $aref->[$i]\n";
> }
> 
> __END__
> 
> When run through the debugger (hence the -d on the shebang), and
> entering the command of 'c', this program gives the following
> debugger output:
> Bizarre copy of ARRAY in leave at ./debug.pl line 7.

That's because perl is trying to do the right thing with bad syntax. 
What you really want to do is

     for ($i=0; $i<=$#$aref; $i++){

I suspect putting the code through Devel::Cover would have the same effect.

Interestingly enough, after browsing through the documentation for a 
while, I couldn't find a discussion on the matter. C<perlref> would be 
the obvious place but it is silent. At the risk of weighing down the 
creaking documentation with another small addition (it's only wafer 
thin), I have attached a small patch which adds an example to C<perlref>.

> The error does not appear if the program is executed outside of
> the debugger.
> 
> The fact that $#{@$aref} is apparently an acceptable alternate
> syntax for $#{$aref} is also bizarre, and seems to be undocumented
> (though that should, perhaps, be a different bug report)

Indeed. It is something that just mostly happens to work.

For instance

   my (@even, @odd);
   push @{ $_ % 2 ? @odd : @even}, $_ for (0..20);
   print "even @even\nodd @odd\n";

is not supposed to work, but it does. (It should be

   push @{ $_ % 2 ? \@odd : \@even}, $_ for (0..20);

in case you were wondering). The @{ ... } to push is supposed to take a 
reference, instead, it's given an array. Surprisingly (to me, at least), 
this works.

Except under the debugger, or Devel::Cover.

David

> 
> [Please do not change anything below this line]
> -----------------------------------------------------------------
> ---
> Flags:
>     category=core
>     severity=low
> ---
> Site configuration information for perl v5.6.1:
> 
> Configured by jcutter at Thu Nov  8 13:16:27 EST 2001.
> 
> Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
>   Platform:
>     osname=solaris, osvers=2.6, archname=sun4-solaris
>     uname='sunos sunnybt1 5.6 generic_111446-02 sun4u sparc sunw,ultra-4 '
>     config_args='-Dprefix=/opt/perl -D cc=gcc -des'
>     hint=recommended, useposix=true, d_sigaction=define
>     usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
>     useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
>     use64bitint=undef use64bitall=undef uselongdouble=undef
>   Compiler:
>     cc='gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
>     optimize='-O',
>     cppflags='-fno-strict-aliasing -I/usr/local/include'
>     ccversion='', gccversion='2.95.2 19991024 (release)', gccosandvers='solaris2.8'
>     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
>     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='gcc', ldflags =' -L/usr/local/lib '
>     libpth=/usr/local/lib /usr/lib /usr/ccs/lib
>     libs=-lsocket -lnsl -ldl -lm -lc
>     perllibs=-lsocket -lnsl -ldl -lm -lc
>     libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
>   Dynamic Linking:
>     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
>     cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'
> 
> Locally applied patches:
>     
> 
> ---
> @INC for perl v5.6.1:
>     /export/home/common/fdcs/DCS_Perl/sun4-solaris
>     /export/home/common/fdcs/DCS_Perl
>     /export/home/common/fdcs/bin
>     /home/plalli/lib/site_perl/5.6.1//sun4-solaris
>     /home/plalli/lib/site_perl/5.6.1/
>     /opt/perl/lib/5.6.1/sun4-solaris
>     /opt/perl/lib/5.6.1
>     /opt/perl/lib/site_perl/5.6.1/sun4-solaris
>     /opt/perl/lib/site_perl/5.6.1
>     /opt/perl/lib/site_perl
>     .
> 
> ---
> Environment for perl v5.6.1:
>     HOME=/home/plalli
>     LANG (unset)
>     LANGUAGE (unset)
>     LD_LIBRARY_PATH=/opt/inf92/lib/esql:/opt/inf92/lib:/usr/lib:/opt/inf92/lib/tools
>     LOGDIR (unset)
>     PATH=.:/home/plalli/bin:/home/jpasqual/setup:/opt/perl/bin:/opt/SUNWspro/bin:/usr/bin:/usr/ccs/bin:.:/home/plalli/local_bin:/opt/inf92/bin:/usr/ucb:/opt/inf92/bin:/usr/bin:/opt:/opt/WorkShop/SUNWspro/bin:/opt/SUNWspro/bin:/usr/dt/bin:/usr/openwin/bin:/bin:/usr/bin:/usr/ucb:/usr/openwin/bin:/usr/ucb:/etc:/usr/local/bin:/usr/ccs/bin:/home/jpasqual/setup:/usr/local/parasoft/bin.solaris:/opt/perl/bin:.
>     PERL5LIB=/export/home/common/fdcs/DCS_Perl:/export/home/common/fdcs/bin:/home/plalli/lib/site_perl/5.6.1/
>     PERL_BADLANG (unset)
>     SHELL=/bin/ksh
> 
> --
> Paul Lalli
> Libris Information Solutions
> 69 State Street
> Albany, NY 12207
> 
> Phone: 518-626-2232
> Cel: 518-312-9362
> Fax:     518-471-1880
> Mail Stop: NY6-100-07-01
> Paul.D.Lalli@BankOfAmerica.com
>  <<ole0.bmp>> 
> 
> Because we value our relationship with you, we would like to offer you the opportunity to "opt out" of future e-mails. If at any time you would like to be removed from my e-mail list, please reply to this message indicating your request.
> 
> This e-mail contains information intended only for the use of the individual or entity named above. If you are not the intended recipient, delete or discard this message. It has been prepared solely for information purposes from sources believed to be reliable, is not intended as specific advice or recommendation, and is not a solicitation, commitment or offer. Although this message and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus-free. We accept no responsibility for any loss or damage arising in any way from its use.
> 
> Regular Internet e-mail is not secure. We ask that you do not send personal or company information of a sensitive or confidential nature through regular e-mail. For questions concerning your account relationships with Bank of America, you may contact us by phone, in person or via our secure "Contact Us" e-mail at www.bankofamerica.com. We do provide encrypted Internet e-mail services for certain online products and services for registered clients.
> 
> Bank of America, 100 N. Tryon Street, Charlotte, NC 28255-0001
> 
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 


-- 
"It's overkill of course, but you can never have too much overkill."



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