[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

[ID 20000119.002] 'next' undefines variables in 'continue' block




This is a bug report for perl from oracle@tauceti.pcr.com,
generated with the help of perlbug 1.26 running under perl 5.00502.


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


A friend of mine ran into this problem, but I never saw it come up 
on perl-porters, so I'm submitting it.

When 'next' exits a while block and enters a following continue
block, it undefines any 'my' variable that was declared and 
initialized within the control expression.  'perlsub' is pretty
clear that the scope extends to the continue block.  A sample:

File test_next:
$^W = 1;
my $x = 3;
while(my $i = $x--) {
   print "while block: \$i = $i\n";
   next if $i == 2;
} continue {
   print "cont. block: \$i = $i\n";
}
Output:

while block: $i = 3
cont. block: $i = 3
while block: $i = 2
Use of uninitialized value at test_next line 5.
cont. block: $i = 
while block: $i = 1
cont. block: $i = 1

Also, when 'next' is used to jump to a labelled outer loop with a
continue block, the same thing happens for variables declared in
the outer block's control expression.

After digging around in the perl source code, it seems that a 
compiled while statement has an unstack op at the end.  Without
a continue block, a next op jumps directly to the beginning of
the while block, skipping the unstack op, and so has to do the
unstacking itself.  With a continue block, the next op jumps right 
into the continue block, but still does the unstacking.

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

---
Site configuration information for perl 5.00502:

Configured by oracle at Thu Feb 11 16:37:09 EST 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 2) configuration:
  Platform:
    osname=solaris, osvers=2.6, archname=sun4-solaris
    uname='sunos tauceti 5.6 generic_105181-03 sun4u sparc sunw,ultra-4 '
    hint=previous, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O', gccversion=
    cppflags='-I/usr/local/include'
    ccflags ='-I/usr/local/include'
    stdchar='unsigned 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=n, prototype=define
  Linker and Libraries:
    ld='cc', 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=true, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='  -R /usr/local/lib/perl5/5.005/sun4-solaris/CORE'
    cccdlflags='-KPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl 5.00502:
    /usr/local/lib/perl5/5.005/sun4-solaris
    /usr/local/lib/perl5/5.005
    /usr/local/lib/perl5/site_perl/5.005/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.005
    .

---
Environment for perl 5.00502:
    HOME=/u/oracle
    LANG (unset)
    LD_LIBRARY_PATH=/usr/dt/lib:/opt/app/oracle/product/8.0.5/lib:/opt/SUNWmotif/lib:/usr/openwin/lib:.:
    LOGDIR (unset)
    PATH=.:/opt/app/oracle/product/8.0.5/bin:/u/oracle/local/bin:/u/oracle/bin:/usr/local/bin:/usr/bin:/etc:/opt/SUNWspro/bin:/usr/ucb:/opt/bin:/usr/ccs/bin:/usr/openwin/bin:/u/Pcr/Bin
    PERL_BADLANG (unset)
    SHELL=/bin/ksh



[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]