[bcn-pm] bug amb until

Stefano Rodighiero stefano.rodighiero a gmail.com
dim ago 23 02:42:56 PDT 2011


2011/8/23 Toni <devegades at gmail.com>:

> Hola mongers,
>
> Mireu que em passa:
>
> $ perl -e 'do { print "hola\n" } until 1'
> hola
> $
>
> OK, és el que esperava.
>
> $ perl -e 'print "hola\n" until 1'
> $
>
> WTF! Perquè no escriu hola?
>
> És un bug meu o del Perl?

It's documented in 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 deprecated "do"-SUBROUTINE statement), in which
    case the block executes once before the conditional is evaluated.

And in perldoc -f do:

    When modified by the "while" or "until" loop modifier, executes
    the BLOCK once before testing the loop condition. (On other
    statements the loop modifiers test the conditional first.)

But I agree this difference could be misleading

s.

-- 
www.stefanorodighiero.net


Més informació sobre la llista de correu Barcelona-pm