Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: take 'n' array elements at a time

by karlgoethebier (Abbot)
on Nov 18, 2014 at 21:44 UTC ( [id://1107654]=note: print w/replies, xml ) Need Help??


in reply to take 'n' array elements at a time

A late TMTOWTDI , perhaps not rock-solid:

#!/usr/bin/env perl use strict; use warnings; use List::MoreUtils qw(natatime); use List::Util qw(reduce); use IO::All; use autodie; my $file = shift; my $amount = 2; my $io = io $file; my $iterator = natatime $amount, @$io; while ( my @items = $iterator->() ) { my @values = map { /^.+\|(.+)$/ } @items; my $sum = reduce { $a + $b } @values; my $average = $sum / $amount; print qq($average\n); } __END__

Update: I took the title of your OP ("...take 'n' at a time...") literally. Or i tried it, at least ;-)

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found