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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem exiting while loop with Term::ReadKey

Status
Not open for further replies.

hazg

Programmer
Dec 14, 2004
10
FR

Hello,

I have a problem! As part of a larger script I am printing out data sent through a socket connection from another pc into the command prompt. While the text is being displayed on screen I want the user to be able to exit this part of the program, ideally with a single key press (say 'x').

I have been trying to get it working with Term::ReadKey but due to the way I am reading in the data from the socket I am never reaching the condition in the while. Here is the code snipet:

----------------------------------------------------------

ReadMode 5; # Turns off controls keys

while(1)
{
while (not defined ($qKey = ReadKey(-1)))
{
while ($client = $peerSock->accept())
{
print "\n\n> Client connected\n\n";

while(defined ($buf = <$client>))
{
print "$buf";
}
}
}
($qKey eq 'x') and last; # Condition which is never reached
}

ReadMode 0; # Reset read mode before exiting

----------------------------------------------------------

Am I on the right line or should I forget about Term::ReadKey and use something else? Any help would be much appreciated. Thanks

 
Have you considered trapping sigint?
The user could use Ctrl-C and you could exit elegantly.



Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top