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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
It works sometimes.

As I do an fdopen, I think it should work each time. Infact: I'm just running below code and it's giving me the expected result now the 20th time.

Here is the (slightly modified) code, which I think should work.

use IO::Handle; use strict; use warnings; my $pos= tell *DATA; my $pid= fork(); die unless defined $pid; if ($pid == 0) { my $x= IO::Handle->new(); $x->fdopen(fileno(DATA), "r"); seek $x, $pos, 0; print "Start c\n"; sleep 4; while (<$x>) { print "c: $_"; sleep 1; } print "stop c\n"; } else { my $y= IO::Handle->new(); $y->fdopen(fileno(DATA), "r"); seek $y, $pos, 0; print "Start p\n"; while (<$y>) { print "p: $_"; sleep 1; } print "waiting for child\n"; wait; print "stop p\n"; } __DATA__ a b c d e


In reply to Re^5: How can I read DATA in parent and child? by Skeeve
in thread How can I read DATA in parent and child? by Skeeve

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2022-12-08 06:06 GMT
Find Nodes?
    Voting Booth?

    No recent polls found