in reply to Re: while
in thread while without parentheses

The following works fine without parentheses, but also in this case is the end of the conditional test of the while statement very clear, i.e. ;

print "$_\n" while <*.*>;

Replies are listed 'Best First'.
Re: Re: Re: while
by perigeeV (Hermit) on Jul 14, 2001 at 17:47 UTC
    You're right of course, but then the while is a modifier to a simple statement. Modifiers are slightly different creatures, for instance you can't use loop control operators or labels with modifiers.
      Here's a curiosity:
      #!/usr/local/bin/perl -w use strict; $_ & 1 ? next : print "$_\n" for 1 .. 10; my $i = 0; $i & 1 ? next : print "$i\n" while ++$i <= 10; __END__ 2 4 6 8 10 Can't "next" outside a block at loops.pl line 8.
      So you can use the loop control operators with the foreach statement modifier, but not with the while statement modifier. I know that these two features were not added to Perl at the same time (perl5.004 for the while statement modifier; perl5.005 for the foreach statement modifier). Perhaps this inconsistent behavior was an oversight.

      (I don't have access to perl5.6 right now, to see if it's the same way.)

        Same result with perl5.6.1 (ActiveState build 626).

        -- Hofmator