Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: How can I read DATA in parent and child?

by tybalt89 (Prior)
on Feb 18, 2019 at 17:13 UTC ( #1230119=note: print w/replies, xml ) Need Help??

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 # 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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1230119]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2022-08-09 23:46 GMT
Find Nodes?
    Voting Booth?

    No recent polls found