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

[perl #20716] scope error with brackets

Thread Next
From:
Dustin Jones
Date:
February 4, 2003 19:09
Subject:
[perl #20716] scope error with brackets
Message ID:
rt-20716-50316.14.8393705671602@bugs6.perl.org
# New Ticket Created by  Dustin Jones 
# Please include the string:  [perl #20716]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=20716 >



This is a bug report for perl from dwjones@spawar.navy.mil,
generated with the help of perlbug 1.26 running under perl 5.00503.


-----------------------------------------------------------------
[Please enter your report here]

I have encountered a bug that involves the changing of scope.  Here is some sample code that demonstrates the problem.

<start code>

1   #!/usr/bin/perl -w
2
3   $x = "outer-scope";
4
5   {
6      my $x = "inner-scope";
7      print "$x[R0]" . "\n";
8      print "${x}[R0]" . "\n";
9      print "${x} [R0]" . "\n";
10  }

<end code>

Results:
Argument "R0" isn't numeric in aelem at ./test.pl line 7.
Use of uninitialized value at ./test.pl line 7.

outer-scope[R0]
inner-scope [R0]

Line 8 should either print an error because it is expecting an array, as line 7 did, or else it should give ${x} as the local value.  Instead it prints the outer scoped variable.

There are many variations of this that can be reproduced, but this is a basic example.
The easy work-around is to escape the brackets around 'R0'.

[Please do not change anything below this line]
-----------------------------------------------------------------

---
Site configuration information for perl 5.00503:

Configured by oper1 at Tue Nov  9 17:08:34 PST 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=solaris, osvers=2.7, archname=sun4-solaris
    uname='sunos yoohoo 5.7 generic_106541-07 sun4u sparc sunw,ultra-enterprise '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='gcc', optimize='-O', gccversion=2.8.1
    cppflags='-I/usr/local/include'
    ccflags ='-I/usr/local/include'
    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
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lc -lcrypt
    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 5.00503:
    tools/config
    ../tools/config
    ../../tools/config
    /export/ui/bridge_spec/tools/config
    /usr/local/lib/perl5/5.00503/sun4-solaris
    /usr/local/lib/perl5/5.00503
    /usr/local/lib/perl5/site_perl/5.005/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.005
    .

---
Environment for perl 5.00503:
    HOME=/homea/dwjones
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/r0/common/rti/RTI-1.3NGv5update4/SunOS-5.7-Sparc-SPRO-5.3-dbg-mt/lib:/quikr0/common/CCSEV1.0.01/CCSEV1.0.01/SimEngineCore/SPEEDES/lib:/quikr0/common/CCSEV1.0.01/CCSEV1.0.01/MDDI/lib:/quikr0/common/JCL_CCSE/JCL/lib:/quikr0/common/Warlib/lib:/quikr0/common/Sne/lib
    LOGDIR (unset)
    PATH=/quikr0/common/CCSEV1.0.01/CCSEV1.0.01/SimEngineCore/SPEEDES/bin:/quikr0/common/CCSEV1.0.01/CCSEV1.0.01/MDDI/bin:/export/ui/bridge_spec/tools/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/opt/SUNWspro/bin:/usr/ucb:/usr/openwin/bin:/app/BridgePoint/bin:/usr/atria/bin/:.:/usr/local/samba/bin:/homea/langford/bin:/usr/mccabe:/usr/ccs/bin:/app/McCabe:/opt/KCC_BASE/kdb/bin:/usr/atria/bin/
    PERLLIB=tools/config:../tools/config:../../tools/config:/export/ui/bridge_spec/tools/config
    PERL_BADLANG (unset)
    SHELL=/bin/csh


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