http://www.perlmonks.org?node_id=996750


in reply to fork and Linux/Windows portability

This should run without change, anywhere there is a threaded perl:

#! perl -slw use strict; use List::Util qw[ sum ]; use threads; sub joinable { threads->list( threads::joinable ) }; sub running { threads->list( threads::running ) }; my @files = map glob, @ARGV; our $T //= 4; my @results; for my $file ( @files ) { async { return `wc -l "$file"`; }; next if running() < 4; push @results, $_->join =~ m[(\d+)] for joinable; sleep 1 while running >= 4; } sleep 1 while running; push @results, $_->join =~ m[(\d+)] for joinable; print "The average number of lines in all the files is:", sum( @results ) / @results; __END__ C:\test>996731 a*.* The average number of lines in all the files is:77346.75

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong