dzhuo wrote:
open files are attributes of a process. after you fork, you have 2
processes, files locks, open handles, as well as pending signals and
such are not shared. ie, when you print to STDOUT in child, it's not the
same STDOUT you expect in parent. why not use a pipe?
#!/usr/bin/perl
use strict;
use warnings;
pipe READH, WRITEH;
fork() ? parent() : child();
sub parent
{
close(WRITEH);
open(FH, ">logifle") || die $!;
#-- 10 lines from child. 1k at a time.
#-- do NOT use <READH> here as it might
#-- block forever looking for newlines
print FH while(read READH, $_, 1024);
close(READH);
close(FH);
}
sub child
{
close(READH);
#-- 10 lines to parent
print WRITEH "line $_\n" for(1..10);
close(WRITEH);
}
__END__
[...]
Thanks. Your program works!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>