Home > Archive > PERL Beginners > January 2006 > stdin not working correctly
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
stdin not working correctly
|
|
| michael 2006-01-30, 9:55 pm |
| I am running the latest (5.8) version of ActivePerl under XP. I tried
executing the following sampel code:
print "What is your name?";
$name = <STDIN>;
print "Your name is: ".$name;
Instead of printing "What is your name?" then asking for input, the
program would always ask for the input first.
| |
| Paul Lalli 2006-01-30, 9:55 pm |
| michael wrote:
> I am running the latest (5.8) version of ActivePerl under XP. I tried
> executing the following sampel code:
>
> print "What is your name?";
> $name = <STDIN>;
> print "Your name is: ".$name;
>
> Instead of printing "What is your name?" then asking for input, the
> program would always ask for the input first.
STDIN is working fine. It is your concept of output buffering (or lack
thereof) that needs work. :-)
By default, output to the console is line-buffered. That is, the
prints are stored in a buffer until a newline is encountered, at which
point everything that had been stored is printed.
You have two options: print a newline after "what is your name", or
turn off output buffering, by setting $| = 1;
See the $| variable in
perldoc perlvar
Paul Lalli
| |
| Marcel 2006-01-31, 6:56 pm |
| I can't see the problem in your code!
Running this skript asks me for my name... And finaly prints it.
I think that's what you were looking for... right?
Marcel
| |
| michael 2006-01-31, 9:55 pm |
| That worked perfectly. Thanks.
|
|
|
|
|