Gossamer Forum
Home : General : Perl Programming :

problem with a script...

Quote Reply
problem with a script...
Code:
ALLOK: {
print "\nWelcome Logan!\n\n";
YORN:
print "If you wish to proceed\npress (Y) otherwise press (N): ";
$input = <STDIN>;
chomp($input);
$input=~ tr/A-Z/a-z/;
if($input eq 'n') {
print "\nSorry, mabye next time :)\n\n";
sleep(3);
exit;
}
unless ($input eq 'y') {
print "\nYou must press Y or N, not $input\n\n";
sleep(2);
goto YORN;
}
if($input eq 'y') {
print "\n\nWelcome Logan!!!";
sleep(3); #HERE IS THE PROBLEM...I THINK
exit;
}
}


what i want this to do, is when the user presses "Y" it prints "Welcome Logan!" and waits 3 seconds and then, naturally, exits...what happens though, is it pauses BEFORE it prints "Welcome Logan"... i have tried reversing where the sleep is, and adding an additional sleep above the Print line..but it does the Sleep command first, then prints...i cant figure out why...any help is appreciated
Quote Reply
Re: [skateboarder83] problem with a script... In reply to
Turn output buffering off

Code:
$| = 1;

And get that goto outta there. You have no reason for it. :)
--mark

Last edited by:

Mark Badolato: Feb 19, 2003, 10:58 PM
Quote Reply
Re: [Mark Badolato] problem with a script... In reply to
where do i put the code you suggested??? but i need the goto to go to a spot when the input is wrong...or is there another way?
Quote Reply
Re: [skateboarder83] problem with a script... In reply to
With Perl TMTOWTDI - There's More Than One Way To Do It (with "it" being anything).

In any language, "goto" is best avoided if there's an alternative method.

If your book hasn't covered program flow yet, you should really be experimenting too much, as it's all too easy to get into bad habits.

It might be dull, but you should follow the book closely before trying to use other features the language provides.