in reply to Process file simultaneously after forking

My problem is how to orchestrate the distribution of the textfile so that the parent grabs a line, the child grabs the next line and so on to EOF.

I've looked into perlipc but am not sure which strategy will work.

You don't say how big/complex the textfile is. Two ways that spring to mind - and which don't require any IPC - are to run a prefilter on the file. You could either just copy the file and then - depending on whether it was the forker or forkee read the odd/even lines. Or you could just slurp the entire file into an array and then use some cuuning manipulations to extract every other line. Something like

my (@odd, @even); map { if($.&1){ push @odd,$_;} else { push @even,$_ } } while(<FILE>);

Dingus


Enter any 47-digit prime number to continue.

Replies are listed 'Best First'.
Re^2: Process file simultaneously after forking
by Aristotle (Chancellor) on Nov 15, 2002 at 16:34 UTC
    Or more succintly,
    my (@odd, @even); push @{ $. & 1 ? \@odd : \@even }, $_ while <FILE>;

    Makeshifts last the longest.