Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Rosetta code: Split an array into chunks

by shevek (Beadle)
on Oct 23, 2010 at 01:31 UTC ( #866914=note: print w/replies, xml ) Need Help??


in reply to Rosetta code: Split an array into chunks

How about an iterator for it?
sub gen_group_array { my ($group,$array) = @_; my ($start,$end) = (0,$group - 1); return sub { my $str = join ' ',@$array[$start..$end]; $start += $group; $end += $group; return $str; }; } my @array = qw(a b c d e f); my $group_size = 2; my $grouping = gen_group_array($group_size,\@array); print $grouping->() . "\n" for 1 .. ($#array+1)/$group_size;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://866914]
help
Chatterbox?
[LanX]: moritz, no ... jsut copy one line of my code
[moritz]: I'm still using the CB, because ambrus's #cbstream makes it bearable
[LanX]: ... the rest is loaded from a node
[holli]: the best course of action would be to transfer the data to something well tested. even if it isnt perl based
[moritz]: but even if I had all the time in the world, I wouldn't spend much on perlmonks
[LanX]: holli: LOL
[LanX]: moritz: why ? family?
[LanX]: or other language?
[moritz]: LanX because of usability issues, and the lack of evolvement
[holli]: lol to the robust charme or to the data transfer?

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2017-11-20 19:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (291 votes). Check out past polls.

    Notices?