Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: fork and Linux/Windows portability

by BrowserUk (Pope)
on Oct 01, 2012 at 21:22 UTC ( #996750=note: print w/ replies, xml ) Need Help??


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


Comment on Re: fork and Linux/Windows portability
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996750]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-08-28 11:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls