I can improve its responsiveness to 0.2 seconds maybe

There is nothing to stop you calling it every 0.001 seconds if you think the typist is likely to enter something significant within that time. Of course, the problem with this kind of architecture is that you have to do you own line buffering, getline-style editing, history etc.

However, here's a more convenient alternative. It uses a thread to send any input from STDIN to a selectable socket. With the advantages that a) you don't need to set up callbacks or artificial timers; b) all the standard command line handling is available to the user; c) line buffering and re-assembly is taken care of:

#! perl -slw use strict; use threads; use IO::Socket; use IO::Select; $|++; sub selectableSTDIN { my $true = 1; my $in = IO::Socket::INET->new( LocalAddr => '127.0.0.1:65521', Proto => "udp", ) or die "Failed to bind port 65521"; ioctl( $in, 0x8004667e, \$true ) or die $!; my $out = IO::Socket::INET->new( PeerAddr => '127.0.0.1:65521', Proto => "udp" ) or die "Failed to bind remote port 65521"; async { $out->send( $_ ) while <STDIN>; }->detach; return $in; } my $sel = IO::Select->new( selectableSTDIN() ); while( 1 ) { for my $src ( $sel->can_read( 0.1 ) ) { print "\n", scalar <$src>; } printf '.'; } __END__ C:\test>selectableSTDIN.pl ...........f.r..e.d.. fred ........b..i....l.l... bill ..........j..o..h..n... . john .......j.a...c...k... jack ........Terminating on signal SIGINT(2)

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

In reply to Re^3: Any event modules that support STDIN polling for Windows? by BrowserUk
in thread Any event modules that support STDIN polling for Windows? by KHLeow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.