in reply to while() {}

There is some inconsistency here?.
While while() as prefix is an infinite loop:
$ perl -MO=Deparse -e 'while() { print "1\n" }' while (1) { print "1\n"; } -e syntax OK
as suffix never executes:
$ perl -MO=Deparse -e 'print "1\n" while ()' print "1\n" while (); -e syntax OK

Casiano

Replies are listed 'Best First'.
Re^2: while() {}
by ikegami (Patriarch) on May 03, 2008 at 10:56 UTC
    The syntax for the suffix notation is
    EXPR while EXPR;
    and not
    EXPR while ( EXPR );

    Therefore, you are comparing apples and oranges.
    In while() { print "1\n" }, the expression is "".
    In print "1\n" while ();, the expression is "()", the empty list, which is false in boolean context.

    You're right about there being an inconsistency, though, just not the one you mentioned.

    >perl -MO=Deparse -e"while() { print 1 }" while (1) { print 1; } -e syntax OK >perl -MO=Deparse -e"print 1 while;" syntax error at -e line 1, at EOF -e had compilation errors.