in reply to while ()

Very interesting. A special-case idiom that never caught on (people still use while(1)). Note that it is a very special case of there being no expression. while(()) and while(do{}) never loop. And you can't mimic the behavior in predicate while, because the parentheses are optional: ... while; is a syntax error, and ... while (); is the same as ... while (());

Update: I didn't mean it's a very special case out of the set of cases where there is no expression; I meant that there being no expression is a very special case (that you can't mimic with any expression). The documentation specifies that while takes an expression.


Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: while ()
by Neutron Jack (Pilgrim) on Jun 08, 2005 at 02:13 UTC
    I don't believe that while(()) is an example of no expression. Rather, while(()) evaluates the condition (), a list of no elements. A list evaluated in scalar conext yields the last element, according to man perldata:
    If you evaluate an array in scalar context, it returns the length of the array. (Note that this is not true of lists, which return the last value, like the C comma operator, nor of built-in functions, which return whatever they feel like returning.)
    What's the "last value" of an empty list? Experiments indicate that it's undef, a false value, so the while-loop doesn't loop.