Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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

by marioroy (Parson)
on Feb 20, 2019 at 02:50 UTC ( #1230210=note: print w/replies, xml ) Need Help??

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

Hi Skeeve,

Update: Ah, the OP wants to read DATA independently. See tybalt89's solution.

Update: Currently, the following demo works on Unix platforms with IO::FDPass: automatically loaded by MCE::Shared if present in Perl. The next update to MCE::Shared on CPAN will support reading from the DATA handle without involving IO::FDPass and work on Windows including Cygwin.

MCE::Shared is not exclusive to only MCE parallel modules: e.g. MCE, MCE::Flow, MCE::Hobo, and etcetera. MCE::Shared also works with threads, even fork shown below, and other parallel modules found on metacpan.


use strict; use warnings; use MCE::Shared; mce_open my $shared_fh, '<', \*DATA; my $pid= fork(); die unless defined $pid; if ($pid == 0) { print "Start Child\n"; while (<$shared_fh>) { print "C: $_"; sleep 1; } print "Stop Child\n"; } else { print "Start Parent\n"; while (<$shared_fh>) { print "P: $_"; sleep 1; } print "Stop Parent\n"; } __DATA__ a b c d e f g h i j


Start Parent Start Child P: a C: b C: c P: d C: e P: f C: g P: h C: i P: j Stop Child Stop Parent

Regards, Mario

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2022-08-09 22:45 GMT
Find Nodes?
    Voting Booth?

    No recent polls found