in reply to Reading line from file only when there is a new line (live)
A simple method is to use IO::Select to watch over the handle. The example below watches STDIN and waits for 5 seconds for a read before passing on.
By playing with parameters you can change the wait time, or make the code wait permanently. Also, by using IO::Handle or the like, you can read in individual characters, instead of whole lines.
#!/usr/bin/perl use IO::Select; my $select = IO::Select->new(); $select->add(\*STDIN); my @ready; while(1) { if(@ready = $select->can_read(5)) { foreach (@ready) { my $line = <$_>; print "Read $line\n"; } } else { print "5 seconds passed without a read\n"; } }
$japh->{'Caillte'} = $me;
|
|---|