Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: The text preceding <STDIN> is not printed

by afoken (Canon)
on Aug 17, 2016 at 19:09 UTC ( #1169941=note: print w/replies, xml ) Need Help??


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

Did you notice that your posting is hard to read when you pressed the PREVIEW button? That's because you did not wrap your code in <code> tags. Not a big problem, you can edit your posting right now, simply insert <code> before your code and </code> after your code.

And by the way, you seem to be suffering from buffering.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
  • Comment on Re: The text preceding <STDIN> is not printed

Replies are listed 'Best First'.
Re^2: The text preceding <STDIN> is not printed
by flowdy (Scribe) on Aug 18, 2016 at 14:07 UTC

    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.

      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…

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1169941]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2020-08-12 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (65 votes). Check out past polls.

    Notices?