in reply to printf in if-statement

Nothing jumps out at me as being wrong in your code, but I do have some stylistic things and best practices you might want to consider...

OK, enough of my opinions.

So the only real question I have is, are you sure that block of code is being reached? I assume you're seeing the printouts to the console, but I just thought I would ask.
Update: I reread the question and saw that the prints are showing up on stdout. I'm out of ideas...

Replies are listed 'Best First'.
Re^2: printf in if-statement
by Utrecht (Novice) on Apr 21, 2009 at 14:21 UTC
    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.
      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))