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


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

Hi karlgoethebier,

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

Update: Currently, the following demos work 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 works similarly with threads and MCE::Hobo.

threads demonstration

use strict; use warnings; use threads; use MCE::Shared; mce_open my $shared_fh, '<', \*DATA; async { print "Start Thread\n"; while (<$shared_fh>) { print "T: $_"; sleep 1; } print "Stop Thread\n"; }; print "Start Parent\n"; while (<$shared_fh>) { print "P: $_"; sleep 1; } print "Stop Parent\n"; $_->join for threads->list; __DATA__ a b c d e f g h i j

MCE::Hobo demonstration

use strict; use warnings; use MCE::Hobo; use MCE::Shared; mce_open my $shared_fh, '<', \*DATA; mce_async { print "Start Child\n"; while (<$shared_fh>) { print "C: $_"; sleep 1; } print "Stop Child\n"; }; print "Start Parent\n"; while (<$shared_fh>) { print "P: $_"; sleep 1; } print "Stop Parent\n"; MCE::Hobo->waitall; __DATA__ a b c d e f g h i j

Regards, Mario