in reply to Prime number generator

I'm getting behavior our of perl I can't explain. Is this acting strangely for anyone else? The following one doesn't print a thing:

{for(2..$p){$i%$_ or$p=0}print$i if$p;$p=$i++,redo}
and neither does:
{for(2..$p){$i%$_ or$p=0}print"$i" if$p;$p=$i++,redo}
but when I try this:
{for(2..$p){$i%$_ or$p=0}print"$i$/" if$p;$p=$i++,redo}
it works just fine. I'm on perl 5.8.7 on both Mandriva Linux and ActiveState.


Christopher E. Stith

Replies are listed 'Best First'.
Re^2: Prime number generator
by rhesa (Vicar) on Jul 22, 2006 at 01:17 UTC
    Are you using the -l command line switch? Are you patient enough? Buffering might prevent the output from appearing straight-ahead. Try adding a $|++; to the start of first two alternatives to make it autoflush.
      It was the buffering. Autoflush made it work like a champ. I simply hadn't considered that. Thanks.


      Christopher E. Stith