Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stdin

Status
Not open for further replies.

Pravit

Programmer
Feb 20, 2005
4
US
Hi,
I'm just starting to learn Perl and I'm a bit confused. I have a program like this:

print "Enter your name!\n";
$name = <STDIN>;
print "Hello $name!\n";

The problem is that when I run it, it sits there waiting for input, after which it will display the "Enter your name" and "Hello" lines. Why is it trying to get input before it has even executed the first line?

Thanks for any help.
 
<STDIN>

is the same as a keyboard, look at it, 18 octaves (j/K)

Was the name thing a clue, it was also the first line of your script

Why is it trying to get input before it has even executed the first line?

mmmm .....

--Paul


cigless ...
 
Please clarify your post a bit.

My program does something like this:

(run)
(does nothing...)
(type in 'John')
JohnEnter your name
Hello John!

Shouldn't it show me "Enter your name" before it waits for my input(e.g. "Enter your name John Hello John!")?
 
try like this

Code:
use strict;
use warnings; 

print "Enter your name: ";

my $name = <STDIN>;
chomp($name);

print "Hello $name!\n";

Tell me what happen
 
It does the same thing:

(does nothing)
(type in gibberish)
fdsfsfdsEnter your name: Hello fdsfsfds!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top