Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by choroba (Archbishop)
on Feb 18, 2019 at 14:13 UTC ( #1230105=note: print w/replies, xml ) Need Help??


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

Interesting. Even duplicating the DATA handle in the child doesn't help.
open my $d2, '<&', *DATA or die $!;

But opening the script itself again works, using tell to find the position of the DATA section:

#!/usr/bin/perl use warnings; use strict; open my $d2, '<', $0 or die $!; seek $d2, tell *DATA, 0; if (fork) { while (<DATA>) { print "parent: $_"; } } else { while (<$d2>) { print "child: $_"; } exit } __DATA__ a b c
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2022-08-09 22:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?