Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Rosetta code: Split an array into chunks

by GrandFather (Sage)
on Sep 25, 2010 at 09:54 UTC ( #861940=note: print w/ replies, xml ) Need Help??


in reply to Rosetta code: Split an array into chunks

I'd have thought the idiomatic Perl solution would splice:

sub chunky { my ($n, @strs) = @_; my $str = ''; $str .= join (' ', splice @strs, 0, $n) . "\n" while @strs; return length $str ? $str : "\n"; }
True laziness is hard work


Comment on Re: Rosetta code: Split an array into chunks
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2015-08-01 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls