Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad interaction between 'next' and raw scope levels #1086

Closed
p5pRT opened this issue Jan 25, 2000 · 3 comments
Closed

bad interaction between 'next' and raw scope levels #1086

p5pRT opened this issue Jan 25, 2000 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 25, 2000

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

Searchable as RT2039$

@p5pRT
Copy link
Author

p5pRT commented Jan 25, 2000

From jcox@newton.interwoven.com

#==============================================================
#==============================================================
#
# Both loops below should output
#
# index​: 0
# index​: 2
#
# But the 1st loop outputs
#
# index​: 0
# index​: 1
# index​: 2
#
# This is wrong, since a raw scope is not loop structure
# (ie​: if/while/foreach...).
#
#
# Sincerely,
# - Jon
# <jcox@​interwoven.com>
#
#==============================================================
#==============================================================

print "\nThe following loops should have the same output -- but they don't!\n";
print "\n\n'next' inside an empty scope within a 'for' loop\n";

for (my $i=0; $i<3; $i++)
{
  { # new "raw" scoping level
  if ($i == 1)
  {
  next; # executes, but does not skip
  } # the print statement! Boo hoo!
  }
  print "index​: $i\n";
}

print "\n\n'next' inside an 'if' within a 'for' loop\n";

for (my $i=0; $i<3; $i++)
{
  if (1)
  { # new scope bound to the "if(1)"
  if ($i == 1)
  {
  next; # correctly skips the print statement
  }
  }
  print "index​: $i\n";
}

Perl Info


Site configuration information for perl 5.00502:

Configured by jcox at Mon Dec  7 18:01:13 PST 1998.

Summary of my perl5 (5.0 patchlevel 5 subversion 2) configuration:
  Platform:
    osname=solaris, osvers=2.6, archname=sun4-solaris
    uname='sunos newton 5.6 generic_105181-07 sun4u sparc sunw,ultrasparc-iii-engine '
    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='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=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=true, libperl=libperl.so
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='  -R /usr/local/lib/perl5/5.00502/sun4-solaris/CORE'
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches:
    


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


Environment for perl 5.00502:
    HOME=/net/stargate/d2/iw/jcox
    LANG (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=.:/usr/local/microsoft/bin:/opt/SUNWspro/bin:/usr/ucb:/net/stargate/d2/iw/jcox/bin/sol:/net/stargate/d2/iw/jcox/bin:/sbin:/bin:/usr/bin:/usr/local/bin:/usr/sbin:/usr/ccs/bin:/usr/openwin/bin:/etc:/usr/etc:/usr/local/etc:/usr/local/jcoxstuff/iw-home/bin:~jcox/bin
    PERL_BADLANG (unset)
    SHELL=/net/stargate/d2/iw/jcox/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Jan 25, 2000

From @tamias

On Tue, Jan 25, 2000 at 09​:49​:52PM -0800, Jonathan Cox wrote​:

for (my $i=0; $i<3; $i++)
{
{ # new "raw" scoping level
if ($i == 1)
{
next; # executes, but does not skip
} # the print statement! Boo hoo!
}
print "index​: $i\n";
}

As documented in perlsyn. Bare blocks, with optional labels, are loops
that execute once. Loop control statements apply to them.

Ronald

@p5pRT
Copy link
Author

p5pRT commented Jan 26, 2000

From @TimToady

Jonathan Cox writes​:
: # This is wrong, since a raw scope is not loop structure

Er, yes it is, in this case. A bare block is defined to be a loop that
executes once.

Larry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant