http://qs321.pair.com?node_id=1230158


in reply to Re^6: How can I read DATA in parent and child?
in thread How can I read DATA in parent and child?

What' even weirder: If I run a sequential verison of the same script, the result is, at least in the last 12104 runs, always correct.

So it's not in the code it must have to do with perl itself.

This is the "serialized" code I used:

#!/usr/bin/perl use IO::Handle; use strict; use warnings; my $pos= tell *DATA; my $x= IO::Handle->new(); $x->fdopen(fileno(DATA), "r"); seek $x, $pos, 0; print "Start c $pos\n"; #sleep 4; while (<$x>) { print "c: $_"; #sleep 1; } print "stop c\n"; my $y= IO::Handle->new(); $y->fdopen(fileno(DATA), "r"); seek $y, $pos, 0; print "Start p $pos\n"; while (<$y>) { print "p: $_"; #sleep 1; } print "stop p\n"; __DATA__ a b c d e

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^8: How can I read DATA in parent and child?
by tybalt89 (Monsignor) on Feb 20, 2019 at 10:33 UTC

    It's not perl, it's the OS. You'd have the same problem with an already open fd in C. DATA is just an open fd on the source file.

    Try a seek DATA, 0, 0; and notice you can read the whole source file.