my @threads = map {
## create the workers passing the log file handle and semaphore
threads->create( \&worker, $log, \$logSem,$_*$N, $_*$N + $N -1);
} 0 .. 5; ## 5 threads each processing 100 "files"
...<hem>that's 6 threads, shirly ?
To process $from..$to in $t threads, how about:
my @threads = map{
threads->create( \&worker, $log, \$logSem, $from + ($_ - 1), $t, $to
+) ;
} 1 .. $t ;
and in the thread:
my( $log, $semRef, $from, $step, $to ) = @_;
for (my $file = $from ; $file <= $to ; $file += $step) {
......
} ;
which deals with the number of files not being an exact multiple of the number of threads, and copes with
$from..$to range where
$from is not zero and
$to is included in the range...