in reply to Need to empty STDIN
#!/usr/bin/perl use warnings; use strict; use IO::Select; # by edan of perlmonks # I just remembered what select says about mixing # buffered reading and "select", so even though the # code works, you might want to substitute # the read via <$fh> with: # my $input; # sysread( $fh, $input, 1024); # loop every 1 second my $timeout = 1; my $s = IO::Select->new(); $s->add( \*STDIN ); while (1) { if ( my @ready = $s->can_read($timeout) ) { # we got input for my $fh (@ready) { my $input = <$fh>; print "got: $input"; } } else { # no input } # just to show that we're looping print scalar localtime; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need to empty STDIN
by bofh_of_oz (Hermit) on May 20, 2005 at 16:11 UTC | |
by zentara (Cardinal) on May 20, 2005 at 18:47 UTC |