Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Rosetta code: Split an array into chunks

by stefan k (Curate)
on Sep 27, 2010 at 08:42 UTC ( [id://862165]=note: print w/replies, xml ) Need Help??


in reply to Rosetta code: Split an array into chunks

Clojure?
(defn pm-chunk [data chsize] (apply str (interleave (map #(apply str (interpose " " %)) (partition chsize chsize nil data)) (repeat \newline))))
Then use it at the REPL:
user=> (print (pm-chunk ["a" "bb" "c" "d" "e" "f" "g" "h"] 3)) a bb c d e f g h
Please note that the rather ugly "apply str" at the top is necessary to fulfil the perlish requirements. Usually you'd stop at creating the right sequence, which is achieved after the call to interleave.

Regards... stefan k
you begin bashing the string with a +42 regexp of confusion

Log In?
Username:
Password:

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

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

    No recent polls found