Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.98k stars 559 forks source link

next and continue in while loop #1184

Closed p5pRT closed 20 years ago

p5pRT commented 24 years ago

Migrated from rt.perl.org#2154 (status was 'resolved')

Searchable as RT2154$

p5pRT commented 24 years ago

From dougw@safeguard.net

Reply-To​: dougw@​safeguard.net

This is a bug report for perl from dougw@​safeguard.net\, generated with the help of perlbug 1.26 running under perl 5.00503.


I thought I submitted this already\, but I've had no response\, so here it is (maybe) again​:

A 'next' statement in a while loop seems to cause any local loop variables to be undefined in a continue block.

# Should print new​: a\,old​: \,new​: b\,old​: a\,new​: c\,old​: b # But all 'old' values are undefined except the first # (which is already initialized and so doesn't count) # Works ok without the 'next;' statement my @​arr=qw(a b c); my $o_val=""; while (my $n_val=pop @​arr) { print "new​: $n_val\n"; print "old​: $o_val\n"; next; } continue { $o_val = $n_val; }



Site configuration information for perl 5.00503​:

Configured by dougw at Mon Feb 14 11​:28​:36 PST 2000.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration​:   Platform​:   osname=hpux\, osvers=10.20\, archname=PA-RISC1.1   uname='hp-ux mongo b.10.20 u 9000800 245239331 unlimited-user license '   hint=recommended\, useposix=true\, d_sigaction=define   usethreads=undef useperlio=undef d_sfio=undef   Compiler​:   cc='cc'\, optimize='-O'\, gccversion=   cppflags='-D_HPUX_SOURCE -Aa -I/usr/local/include'   ccflags ='-D_HPUX_SOURCE -Aa -I/usr/local/include'   stdchar='unsigned char'\, d_stdstdio=define\, usevfork=false   intsize=4\, longsize=4\, ptrsize=4\, doublesize=8   d_longlong=undef\, longlongsize=\, d_longdbl=define\, longdblsize=16   alignbytes=8\, usemymalloc=n\, prototype=define   Linker and Libraries​:   ld='ld'\, ldflags =' -L/usr/local/lib'   libpth=/usr/local/lib /lib/pa1.1 /lib /usr/lib /usr/ccs/lib   libs=-lnsl_s -lndbm -lmalloc -ldld -lm -lc -lndir -lcrypt   libc=/lib/libc.sl\, so=sl\, useshrplib=false\, libperl=libperl.a   Dynamic Linking​:   dlsrc=dl_hpux.xs\, dlext=sl\, d_dlsymun=undef\, ccdlflags='-Wl\,-E -Wl\,-B\,deferr ed '   cccdlflags='+z'\, lddlflags='-b -L/usr/local/lib'

Locally applied patches​:  


@​INC for perl 5.00503​:   /home/dougw/perl/lib/5.00503/PA-RISC1.1   /home/dougw/perl/lib/5.00503   /home/dougw/perl/lib/site_perl/5.005/PA-RISC1.1   /home/dougw/perl/lib/site_perl/5.005   .


Environment for perl 5.00503​:   HOME=/home/dougw   LANG (unset)   LANGUAGE (unset)   LD_LIBRARY_PATH (unset)   LOGDIR (unset)

PATH=/home/dougw/bin​:/home/dougw/perl/bin​:/usr/bin​:/opt/ansic/bin​:/usr/ccs/b in​:/usr/contrib/bin​:/opt/nettladm/bin​:/opt/pd/bin​:/usr/bin/X11​:/usr/contrib/ bin/ X11​:/opt/upgrade/bin​:/opt/perf/bin​:/opt/hpnp//bin​:/opt/dtcmgr/sbin​:/opt/hpar ray/ bin​:/opt/rdtcmgr/sbin​:/bin​:/opt/langtools/bin​:/opt/imake/bin​:/opt/pred/bin​:/ opt/ ignite/bin​:/opt/resmon/bin​:/usr/bin​:/usr/ccs/bin​:/usr/contrib/bin​:/opt/nettl adm/ bin​:/usr/bin/X11​:/usr/contrib/bin/X11​:/opt/upgrade/bin​:/opt/hpnp/bin​:/usr/lo cal/ bin​:/opt/perl5/bin​:/scope/cvs/cvsroot/bin​:/opt/fourgen731/bin​:/opt/informix7 30/b in​:/scope/dev/all.4gm/lib.4gs​:/scope/dev/scripts​:.   PERL_BADLANG (unset)   SHELL=/usr/bin/sh

p5pRT commented 24 years ago

From @gsar

On Tue\, 15 Feb 2000 16​:21​:47 PST\, Doug Wilson wrote​:

This is a bug report for perl from dougw@​safeguard.net\, generated with the help of perlbug 1.26 running under perl 5.00503. [...] I thought I submitted this already\, but I've had no response\, so here it is (maybe) again​:

A 'next' statement in a while loop seems to cause any local loop variables to be undefined in a continue block.

# Should print new​: a\,old​: \,new​: b\,old​: a\,new​: c\,old​: b # But all 'old' values are undefined except the first # (which is already initialized and so doesn't count) # Works ok without the 'next;' statement my @​arr=qw(a b c); my $o_val=""; while (my $n_val=pop @​arr) { print "new​: $n_val\n"; print "old​: $o_val\n"; next; } continue { $o_val = $n_val; }

This has been fixed in v5.5.650 for the 5.6 release.

Sarathy gsar@​ActiveState.com