内置的Perl是系统调用select()
的传递select()
,但我推荐的是理智的人IO::Select
.
代码示例:
#!/usr/bin/perl use IO::Select; $s = IO::Select->new(); $s->add(\*STDIN); while (++$i) { print "Hiya $i!\n"; sleep(5); if ($s->can_read(.5)) { chomp($foo =); print "Got '$foo' from STDIN\n"; } }