Hello. I am just beginning to learn Perl, and I'm having a problem using <STDIN> to get input from the user. Whenever I use <STDIN> in a program (no matter where it appears in the program), the system stops when the program is executed and waits for a response. For example, in this program:
#! C:\Perl
print "Enter a number: ";
$number = <STDIN>;
print "You entered $number";
The system just stops when the program is executed (It does not display the prompt first). If I type a number, then it displays the prompt and continues to execute. How can I fix this problem so that the programs will execute normally. I'm using a Windows XP machine, the ActivePerl port of Perl 5.8, and the Open Perl IDE. I'll try to provide addition information if necessary, but if this issue is not resolved I will not be able to use <STDIN> at all. I was told that placing the following lines before the rest of a program would fix this problem:
use IO::Handle;
STDOUT -> autoflush(1);
STDERR -> autoflush(1);
However, using this method causes the program to accept any characters on the same line as the entered data as the intended input (including the prompt). Does anyone know a way to fix this STDIN problem? Thank you very much.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.