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

chanakya has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I have a script which forks 3 childs at a given time and this is taken care by Proc::Queue.
Everything worked fine until I moved the line "next if" above the Proc::Queue::run_back_now{} method

After the above change the script spawns unlimited childs. For example, I have an array of 50 files
the script spawns 50 childs.

Is this the problem of Proc::Queue or is this script error. Below is my code
#!/usr/bin/perl -w use POSIX 'WNOHANG'; use Proc::Queue ':all'; use Getopt::Long 'GetOptions'; my $numChilds=3; GetOptions( 'childs|c=i' => \$opt_numChilds , 'help|h' => \&USAGE ) || USAGE() ; ($opt_numChilds) ? $numChilds=$opt_numChilds : $numChilds; Proc::Queue::size($numChilds); #update my $src="/data/files"; my @allfiles = ("$src/file1", "$src/file2", "$src/file3","$src/file4", +"$src/file5","$src/file6"); my $log = "/tmp/data.log"; open(STAT, $log) || die ("Can't open file $log: $!"); my @pids; foreach my $file (@allfiles) { my ($root=$file); ($root=$file)=~tr/a-z/A-Z/; next if (!-f"$srcdir/ok"); push @pids, Proc::Queue::run_back_now{ #code here system("dataload.pl -file $file > file.err 2>&1"); }; } waitpids(@pids); close STAT; exit;
Many thanks