Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by marioroy (Prior)
on Feb 20, 2019 at 03:05 UTC ( [id://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 (Abbot) on Feb 20, 2019 at 19: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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1230211]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-18 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found