MisterH has asked for the wisdom of the Perl Monks concerning the following question:
It's a basic realtime chat client. It's not entirely bulletproof and it's not very efficient because it reads the whole say.txt file every 2 seconds. I can work on these limitations later.#!/usr/bin/perl use Term::ReadKey; until ($Name){ print "Your callsign?>"; chomp ($Name = <>); if ($Name) { print "say: !! to exit\n\n"; open (TX, ">>d:/telnet/say.txt"); printf TX time." $Name entered.\n"; close (TX); } } $Lastime = time; while($key.$Input ne "!!"){ open (RX, "<d:/telnet/say.txt"); @Said = <RX>; close (RX); foreach $Said(@Said){ $Said =~ m/(^\d+)(\s[\D \d]*)/; if ($1 >= $Lastime){ print $2; Tmptime = $1; } } $Lastime = $Tmptime + 1; if ($key = ReadKey 2){ print $key; if (ord($key) != 13){ chomp($Input = <>); } else { $key=""; $Input = ""; } open (TX, ">>d:/telnet/say.txt"); printf TX time." $Name said: $key$Input\n"; close (TX); } } open (TX, ">>d:/telnet/say.txt"); printf TX time." $Name left.\n"; close (TX); print "\n\nBye.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Non Blocking input on Win32 platforms
by BrowserUk (Patriarch) on Oct 31, 2008 at 13:23 UTC | |
by TGI (Parson) on Oct 31, 2008 at 21:41 UTC | |
by BrowserUk (Patriarch) on Nov 01, 2008 at 04:10 UTC | |
by TGI (Parson) on Nov 01, 2008 at 17:35 UTC | |
by zentara (Cardinal) on Nov 01, 2008 at 13:06 UTC | |
by BrowserUk (Patriarch) on Nov 01, 2008 at 14:31 UTC | |
by zentara (Cardinal) on Nov 01, 2008 at 16:40 UTC | |
|
Re: Non Blocking input on Win32 platforms
by zentara (Cardinal) on Oct 31, 2008 at 11:35 UTC | |
|
Re: Non Blocking input on Win32 platforms
by zentara (Cardinal) on Nov 01, 2008 at 19:29 UTC |