Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-06-24 23:01 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.