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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1230119]
help
Chatterbox?
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
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?