http://qs321.pair.com?node_id=1230119


in reply to How can I read DATA in parent and child?

If you want, you can read alternately in the parent and the child.

(Using sysread because it is unbuffered.)

#!/usr/bin/perl # https://perlmonks.org/?node_id=1230099 use strict; use warnings; $| = 1; my $me = fork() ? 'parent' : ' child'; while( sysread DATA, $_, 1 ) { print $me eq 'parent' ? uc : lc; select undef, undef, undef, 0.1; } 1 while wait > 0; __DATA__ one two three four five six seven eigth nine ten

Outputs (on my machine) :

OnE TwO ThReE FoUr fIvE SiX SeVeN EiGtH NiNe tEn

Posted because I think it's funny :)

EDIT: fixed incomplete output paste.