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

[perl #21737] Variable scope affects variable interpretation with shell brace escapes

Thread Next
From:
perlbug-followup
Date:
March 28, 2003 21:35
Subject:
[perl #21737] Variable scope affects variable interpretation with shell brace escapes
Message ID:
rt-21737-54235.10.8304340343871@bugs6.perl.org
# New Ticket Created by  ckuskie@dalsemi.com 
# Please include the string:  [perl #21737]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=21737 >



This is a bug report for perl from ckuskie@dalsemi.com,
generated with the help of perlbug 1.33 running under perl v5.6.1.


-----------------------------------------------------------------

#!/usr/local/bin/perl

$a = "name";
$b = 5;

my $c = "name";
my $d = 5;

print ".D(${a}[$b])\n";
print ".D(${c}[$d])\n";

outputs:

.D(name[5])
.D([5])

When -w is turned on, then you get this:

Name "main::c" used only once: possible typo at ./braces_lexical_scope line 10.
.D(name[5])
Use of uninitialized value in concatenation (.) or string at ./braces_lexical_scope line 10.
.D([5])

I've tried this on both 5.6.1 and 5.8.0 on Solaris 2.8, as well as Linux.

It's not a bad problem, because you can avoid it by escaping the bracket like this:

print ".D(${c}\[$d])\n";

But it's very non-intuitive.

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

Configured by gewax at Tue Jun 18 10:52:30 CDT 2002.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=solaris, osvers=2.8, archname=sun4-solaris
    uname='sunos ecad7 5.8 generic_108528-07 sun4u sparc sunw,ultra-60 '
    config_args='-Dcc=gcc'
    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.3 20010315 (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 -lgdbm -ldb -ldl -lm -lc -liconv
    perllibs=-lsocket -lnsl -ldl -lm -lc -liconv
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -Wl,-E'
    cccdlflags='-fPIC', lddlflags=' -W,l-E -G -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.6.1:
    /users/ckuskie/perl/modules/sun4-solaris
    /users/ckuskie/perl/modules
    /design/nwdc/libs/usr/local/lib/perl5/site_perl/5.005/sun4-solaris
    /design/nwdc/libs/usr/local/lib/perl5/site_perl/5.005
    /design/nwdc/libs/usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris
    /design/nwdc/libs/usr/local/lib/perl5/site_perl/5.6.1
    /usr/local/lib/perl5/5.6.1/sun4-solaris
    /usr/local/lib/perl5/5.6.1
    /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.6.1
    /usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.6.0
    /usr/local/lib/perl5/site_perl/5.005/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.005
    /usr/local/lib/perl5/site_perl
    .

---
Environment for perl v5.6.1:
    HOME=/users/ckuskie
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/design/nwdc/libs/usr/local/mozilla:/users/ckuskie/lib:/usr/local/lib:/usr/lib:/usr/openwin/lib:/usr/dt/lib:/cad/release/site/lib:/engtools/avanti/meta/2000.2/sol4:/engtools/cadence/opus/IC443/tools/lib:/engtools/cadence/ldv3.1/tools/lib:/usr/ucblib
    LOGDIR (unset)
    PATH=/users/ckuskie/bin:/usr/local/bin:/usr/local/sbin:/usr/openwin/bin:/usr/sbin:/usr/bin:/usr/ccs/bin:/engtools/avanti/adm/98.2/sun4_u5:/engtools/dai/sigscan/5.3/bin/sparc-solaris:/engtools/dai/comparescan/1.4/bin/sparc-solaris:/engtools/avanti/meta/2000.2/bin:/engtools/avanti/meta/2000.2/sol4:/lsf/bin:/engtools/sync/rel31/syncinc/bin:/engtools/netscape/communicator4.75:/engtools/cadence/assura/assura2.0.18/tools/assura/bin:/engtools/cadence/assura/assura2.0.18/tools/bin:/engtools/cadence/opus/IC443/tools/dfII/bin:/engtools/cadence/opus/IC443/tools/verilog/bin:/engtools/cadence/opus/IC443/tools/bin:/engtools/cadence/opus/IC443/tools/pbs/bin:/engtools/cadence/ldv3.1/tools/bin:/engtools/cadence/cct/ICC4.0/tools.sun4v/iccraft/bin:/engtools/veritools/undertow/ut8.1.8b3:/engtools/adobe/frame/5.5.3/bin:/engtools/cadence/Ambit/ambit4.0.2/BuildGates/v04.00-s011/bin:/usr/ucb:/design/nwdc/libs/usr/local/bin:/usr/dslocal/bin:.:/users/ckuskie/projects/DSB17/bin
    PERL5LIB=/users/ckuskie/perl/modules:/design/nwdc/libs/usr/local/lib/perl5/site_perl/5.005:/design/nwdc/libs/usr/local/lib/perl5/site_perl/5.6.1
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/tcsh


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