Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by choroba (Bishop)
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
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 pondering the Monastery: (3)
As of 2019-03-23 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How do you Carpe diem?





    Results (114 votes). Check out past polls.

    Notices?