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

Hello, i dont know where i can post my problem. I hope you can help me.
$|=1; my $recv = 0; while(1) { $recv++; if($recv > 200) { print "<!-- //--> "; undef $recv; } open(FIFO,"<fifo"); my @read = <FIFO>; close(FIFO); foreach(@read) { ............ } sleep 1; }
If i start this program it reads from a PIPE. But it waits so long till the program reads from a PIPE and THEN goes again trough the Loop. But i want that: Go trough loop , read from pipe , sleep 1 second and then start the loop again. I hope you can help me , sorry for my bad english.

Replies are listed 'Best First'.
Re: Fifos + Pipes
by jonadab (Parson) on Oct 02, 2003 at 13:22 UTC

    If you want to get through that loop and actually get to any of the code below that reads from the fifo, you'll need a much faster processor, preferably a quantum computer. Otherwise, you might try putting code that reads from the pipe inside the loop, or something, or maybe last if $recv > $somemaximumvalue. update: but that won't work if you reset $recv to 0 before it reaches the max value. I think what you really want is to read a line inside the loop.

    If i start this program it reads from a PIPE. But it waits so long till the program reads from a PIPE and THEN goes again trough the Loop.

    No, you have that backwards. It's doing the reverse: going through the loop first before it opens the pipe. Since the loop never exits, the pipe is never read.


    $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
Re: Fifos + Pipes
by Anonymous Monk on Oct 03, 2003 at 10:12 UTC
    I think there is nothing to read in this "fifo". The process is waiting for a CR which is never arriving.

    For your tests use a textfile instead of "fifo".

    Use a string $read instead of a array @read.

    If this is unsuccessful use the debug-mode of the perl-interpreter.

    Good luck

    rolf