in reply to for vs. while question

Move your expression from third position to the first position:
for (my @socks = $BASKET -> can_read(2); ; ) { ... }
In the place you put it, it's executed at the bottom of the loop, not the top.

-- Randal L. Schwartz, Perl hacker


update: No, read further down.

Replies are listed 'Best First'.
Re: Re: for vs. while question
by MrNobo1024 (Hermit) on Mar 07, 2001 at 05:50 UTC
    Won't that put it outside of the loop (so it's only executed once)?
      Blimey yes. Ugh. OK, make it the conditional then:
      for (;$BASKET and (my @socks = $BASKET -> can_read(2)) or 1); ) { ... }
      and now it's nearly like the original non-for code.

      Probably simpler just to use the while. {grin}

      -- Randal L. Schwartz, Perl hacker