Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996750]
and snow settles gently...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2017-06-22 18:59 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (528 votes). Check out past polls.