in reply to Checking number of lines in bzipped file

Does your "reading" part work without the call to fork?

Personally, I would just use a pipe from bzcat to read the file instead:

open my $fh, "bzcat '$file' |" or die "Couldn't spawn [bzcat '$file']: $! / $?"; while (<$fh>) { $number_of_lines++ };

Once that works, look at either using Dominus' runN script or re-wrap your script with the routine doing the "fork" calls. Alternatively, you can also look at Parallel::ForkManager to rate-limit your child programs.

Replies are listed 'Best First'.
Re^2: Checking number of lines in bzipped file
by Anonymous Monk on Apr 25, 2011 at 18:31 UTC

    I like that :-) I was using Compress::Bzip2 because I couldn't figure out how to capture both STDOUT and STDERR from "bzcat <file> | wc -l". This gives me both :-) (And I've found other solutions by googling just now, too) The entry under "qx" in perlop says it's "easiest" to re-direct them to files and then read the files in again, and I mistakenly understood "easiest = only way" :-(