Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by marioroy (Priest)
on Feb 19, 2019 at 22:05 UTC ( #1230211=note: print w/replies, xml ) Need Help??


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

Replies are listed 'Best First'.
Re^3: How can I read DATA in parent and child?
by karlgoethebier (Monsignor) on Feb 20, 2019 at 14:46 UTC

    Thank you Mario. Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2019-03-22 03:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How do you Carpe diem?





    Results (110 votes). Check out past polls.

    Notices?