in reply to Re: The text preceding <STDIN> is not printed
in thread The text preceding <STDIN> is not printed

Why should that be the case? I read on the linked page that print() calls on terminal is line buffered, so why there is buffering asks for another reason. Or is this phanomenon platform-dependent?

If you run this, you find that it works the way you expect: The prompt appears on the screen right away. Where's the buffering? Why didn't Perl save up the output until it had a full buffer? Because that's almost never what you want when you're writing to a terminal, the standard I/O library that Perl uses takes care of it for you. When a filehandle is attached to the terminal, as STDOUT is here, it is in line buffered mode by default. A filehandle in line buffered mode has two special properties: It's flushed automatically whenever you print a newline character to it, and it's flushed automatically whenever you read from the terminal. The second property is at work here: STDOUT is flushed automatically when we read from STDIN.

Short test:

% perl print "Hi. Your name, please: "; chomp( my $name = <STDIN> ); print "Oh, $name, I think I am your system. Glad to be at your service +.\n"; # Press CTRL-D or whatever shortcut to trigger EOF Hi. Your name, please: Florian Oh, Florian, I think I am your system. Glad to be at your service.

Replies are listed 'Best First'.
Re^3: The text preceding <STDIN> is not printed
by soonix (Chancellor) on Aug 19, 2016 at 10:03 UTC

    The OP states in Re: The text preceding <STDIN> is not printed that it helped.

    Perhaps he runs his Perl scripts from a special environment, e.g. an IDE, which tees the script's STDOUT, so that Perl doesn't recognize it as a terminal any more…