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

do { ... }->method while... #2396

Closed
p5pRT opened this issue Aug 17, 2000 · 2 comments
Closed

do { ... }->method while... #2396

p5pRT opened this issue Aug 17, 2000 · 2 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 17, 2000

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

Searchable as RT3743$

@p5pRT
Copy link
Author

p5pRT commented Aug 17, 2000

From @pjscott

This I expect (do blocks are always executed once)​:

$ perl -le 'do {$x=42} while 0; print $x'
42

This I don't expect​:

$ perl -le 'do {$x=42}->foo while 0; print $x'

$

Either it's a bug that it doesn't execute the block or it's a bug that it
doesn't flag it as a syntax error.

This is more understandable​:

$ perl -le 'do {$x=42}->foo while 1; print $x'
Can't call method "foo" without a package or object reference at -e line 1.

But I don't see why it should make a difference whether the while condition
is true.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration​:
  Platform​:
  osname=linux, osvers=2.2.14-5.0, archname=i586-linux
  uname='linux psdt.com 2.2.14-5.0 #1 tue mar 7 20​:53​:41 est 2000 i586
unknown '
  config_args=''
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
  useperlio=undef d_sfio=undef uselargefiles=define
  use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler​:
  cc='cc', optimize='-g', gccversion=egcs-2.91.66 19990314/Linux
(egcs-1.1.2 release)
  cppflags='-DDEBUGGING -fno-strict-aliasing'
  ccflags ='-DDEBUGGING -fno-strict-aliasing -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64'
  stdchar='char', d_stdstdio=define, usevfork=false
  intsize=4, longsize=4, ptrsize=4, doublesize=8
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib
  libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
  libc=/lib/libc-2.1.3.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
  cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Characteristics of this binary (from libperl)​:
  Compile-time options​: DEBUGGING USE_LARGE_FILES
  Built under linux
  Compiled at May 3 2000 12​:54​:39
  @​INC​:
  /usr/lib/perl5/5.6.0/i586-linux
  /usr/lib/perl5/5.6.0
  /usr/lib/perl5/site_perl/5.6.0/i586-linux
  /usr/lib/perl5/site_perl/5.6.0
  /usr/lib/perl5/site_perl/5.005
  /usr/lib/perl5/site_perl
  .

@p5pRT
Copy link
Author

p5pRT commented Aug 17, 2000

From [Unknown Contact. See original ticket]

On Thu, Aug 17, 2000 at 06​:02​:09PM -0700, "Peter Scott" wrote​:

This I expect (do blocks are always executed once)​:
$ perl -le 'do {$x=42} while 0; print $x'
42
This I don't expect​:
$ perl -le 'do {$x=42}->foo while 0; print $x'

I don't consider this a bug.

From perlsyn​:

  . . . The
  while and until modifiers have the usual "while loop"
  semantics (conditional evaluated first), except when
  applied to a do-BLOCK (or to the now-deprecated
  do-SUBROUTINE statement), in which case the block executes
  once before the conditional is evaluated. This is so that
  you can write loops like​:

  do {
  $line = <STDIN>;
  ...
  } until $line eq ".\n";

In the case of​:

$ perl -le 'do {$x=42} while 0; print $x'

In this case, the clause is most definately a "do-BLOCK."

$ perl -le 'do {$x=42}->foo while 0; print $x'

In this case, the clause is a complex expression, which may as well
be​:

  $ perl -le 'while (0) { do {$x=42}->foo }; print $x'

See the difference?

The do-BLOCK used with the while/until suffix is a very special case
to make it easier for people familiar with languages such as C++ to obtain
the behaviour they desire. This is necessary because of the unfortunate
decision of "do { ... }" to be allowed in arbitrary expressions to
effect a complex statement returning a single list value, being ambiguous
with the "statement while/until cond;" special cutesy syntax.

mark

--
markm@​nortelnetworks.com/mark@​mielke.cc/markm@​ncf.ca __________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | SIR Tools (7H12)
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Nortel Networks
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
  and in the darkness bind them...

  http​://mark.mielke.cc/

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