http://www.perlmonks.org?node_id=478096

rabbit7 has asked for the wisdom of the Perl Monks concerning the following question:

select() is only blocking the first time it gets executed. I want it to block everytime though, what am i doing wrong ?
#!/usr/bin/perl -w use strict; use POSIX qw(mkfifo); use Fcntl qw(O_RDONLY O_NONBLOCK); my $fifofile = "fifo"; my $inputbuf; unlink($fifofile); mkfifo($fifofile, 0666) or die (' can\'t create FIFO:'.$fifofile); sysopen(FIFOFD, $fifofile, O_RDONLY | O_NONBLOCK ) or die ("can\'t rea +d FIFO:'.$fifofile"); while (1){ my $rin =''; vec($rin,0,1)=1; vec($rin,fileno(FIFOFD),1)=1; select( $rin, undef, undef, undef ); print "select returning\n"; my $fromfifo; while ( sysread(FIFOFD, $fromfifo, 1) == 1 ){ $inputbuf .= $fromfifo ; } my $command; my $index; while ( $index = index($inputbuf,"\n" )+1 ){ my $command = substr($inputbuf,0,$index,""); if ( defined ($command) ) { print $command; } } }