in reply to Event timing and input processing
Simplicity itself using [cpan://threads]. #! perl -slw use strict; use threads qw[ async ]; use Thread::Queue; my $Qin = new Thread::Queue; async { my $input; do { chomp( $input = <STDIN> ); $Qin->enqueue( $input ); } until $input =~ m[^Q(?:uit)?]i; }->detach; my %events; while( sleep 1 ) { if( $Qin->pending ) { my $input = $Qin->dequeue ; last if $input =~ m[^Q(?:uit)?]i; ## Process input print "Got: $input"; } ## process timer based stuff if( exists $events{ scalar localtime } ) { ## Processing event } }
|
|---|