in reply to Re: printf in if-statement
in thread printf in if-statement

Hi, thank you for your input. I am sorry I was bothering you, because I think I was a little too hasty with my question. For some reason, the print-statement is not executed realtime, but only after the while over filehandle INP is finished. I don't understand why this buffering occurs in this case as normally it doesn't, but the code works fine anyway.

Replies are listed 'Best First'.
Re^3: printf in if-statement
by almut (Canon) on Apr 21, 2009 at 14:49 UTC
    I don't understand why this buffering occurs in this case as normally it doesn't

    I'd say it's the other way around: buffering is the default behaviour. Only under certain circumstances, the behaviour is changed, for example when the handle is connected to a terminal (like STDOUT, typically). In this case, line-buffering (as opposed to block-buffering) is used, because an interactive mode of operation is assumed.

    You could enable auto-flushing, though (on any handle):

    use IO::Handle; open my $fh, ">", "test.out" or die $!; $fh->autoflush(); print $fh "..."; # is being written immediately

    (see also Re: Troubles with do...while loop and sleep (line- vs. block-buffered))