develooper Front page | perl.beginners | Postings from December 2002

Joining with a basic question

Thread Next
From:
Andrew F.
Date:
December 2, 2002 18:05
Subject:
Joining with a basic question
Message ID:
004d01c29a6f$f7171e50$1302a8c0@KALDRENON
Hello all. My name is Andrew.

    I might as well get right to it. I'm writing a real basic script, since I'm still learning Perl. It looks like this:


print "Input a name: ";                      #Prompt for a name
sleep .5;
$name1 = <STDIN>;                            #User input

print "\nInput another name:";               #Second prompt
sleep .5;
$name2 = <STDIN>;                            #Second input

if ($name1 eq $name2) {;                     #Compares two variables and returns
    print "\nThese are the same.";           # whether or not they are similar
    }
  else {;
    print "\nThere are not the same.";
    };

The problem is, when I run this, it asks for the input before it prints the visible prompt. In other words, it treats it as if it were ordered:

$name1 = <STDIN>;                            #User input
$name2 = <STDIN>;                            #Second input
print "Input a name: ";                      #Prompt for a name
sleep .5;
print "\nInput another name:";               #Second prompt
sleep .5;

Does anyone know why it does this or how to prevent it?

Thanks, 
    Andrew


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About