in reply to How can I read DATA in parent and child?
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
|
---|