1 @STATE = split //, ".URRUUxR"; 2 @data = split//,"\nrekcah xinU / lreP rehtona tsuJ"; 3 4 sub make_pipe_and_fork { 5 @pipestate{"r$fhno", "u$fhno"}=(P,P); 6 pipe "r$fhno", "u$fhno"; 7 ++$fhno; 8 ($pid *= 2) += $is_child = !fork(); 9 map { 10 $STATE=$STATE[$is_child | ord($pipestate{$_}) & 6]; 11 $pipestate{$_} = (/^$STATE/i ? $STATE : close $_); 12 } keys %pipestate 13 } 14 make_pipe_and_fork; 15 make_pipe_and_fork; 16 make_pipe_and_fork; 17 make_pipe_and_fork; 18 make_pipe_and_fork; 19 20 map { 21 $pipestate{$_} =~ /^[P.]/ && close $_ 22 } %pipestate; 23 24 wait until $?; 25 26 map { /^r/ ? <$_> : 1 } %pipestate; 27 28 $_ = $data[$pid]; 29 sleep rand(2) if /\S/; 30 print