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

Hello, I am trying to learn about the fork process .
I found this snippet of code so I may learn more about the
process but I do not understand it . Can anyone explain how the below snippet works?
@STATE = split //, ".URRUUxR"; @data = split//,"\nrekcah xinU / lreP rehtona tsuJ"; sub make_pipe_and_fork { @pipestate{"r$fhno", "u$fhno"}=(P,P); pipe "r$fhno", "u$fhno"; ++$fhno; ($pid *= 2) += $is_child = !fork(); map { $STATE=$STATE[$is_child ^ ord($pipestate{$_}) & 6]; $pipestate{$_} = (/^$STATE/i ? $STATE : close $_); } keys %pipestate } make_pipe_and_fork; make_pipe_and_fork; make_pipe_and_fork; make_pipe_and_fork; make_pipe_and_fork; map { $pipestate{$_} =~ /^[P.]/ && close $_ } %pipestate; wait until $?; map { /^r/ ? <$_> : 1 } %pipestate; $_ = $data[$pid]; sleep rand(2) if /\S/; print

Replies are listed 'Best First'.
Re: fork process
by JavaFan (Canon) on Nov 28, 2010 at 23:35 UTC
    It's a JAPH. It's written to be obscure. It's not good code to learn something about pipes and forks. And if you have to ask others, it's more efficient it you ask about reasonable (that is, non-obscure) code.