note
marioroy
<p>Hi [Skeeve],</p>
<p><b>Update:</b> Ah, the OP wants to read DATA independently. See [tybalt89]'s [id://1230233|solution].</p>
<p><b>Update:</b> 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.</p>
<p>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.</p>
<p><b>Code</b></p>
<code>
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
</code>
<p><b>Output</b></p>
<code>
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
</code>
<p>Regards, Mario</p>
1230099
1230099