Obviously the problems on line 23 in your code which you've helpfully provided so . . . oh. Never mind.
Vague handwaving: presuming all the sub-hashes are the same size (in your example four key/value pairs) you could trivially do it with splice to pull off 8 elements and then push a new hashref onto your list. Your problems with only having the items from the last set means that you're probably declaring a lexical hash in the wrong enclosing scope rather than somewhere it'll be unique for each set. But again, no code so that's just a slightly educated guess.
Update:
#!/usr/bin/env clj
(ns split-sample
(:use [clojure.contrib.str-utils :only (re-split)]
[clojure.contrib.seq-utils :only (flatten)]
clojure.contrib.pprint))
(def string "a=1,b=5,c=8,d=89, a=5,b=65,c=8,d=19, a=41,b=98,c=8,d=34,
+a=341,b=125,c=3,d=19, a=65,b=23,c=8,d=70")
(println (str "string:\n" string))
(def outbuff (java.io.StringWriter.))
(binding
[*out* outbuff]
(pprint (for [chunk (partition 4 (partition 2 (re-split #"=|,\s*" st
+ring)))]
(apply hash-map (flatten chunk)))))
(println (str "munged:\n" outbuff))
(System/exit 0)
; string:
; a=1,b=5,c=8,d=89, a=5,b=65,c=8,d=19, a=41,b=98,c=8,d=34, a=341,b=125
+,c=3,d=19, a=65,b=23,c=8,d=70
; munged:
; ({"a" "1", "b" "5", "c" "8", "d" "89"}
; {"a" "5", "b" "65", "c" "8", "d" "19"}
; {"a" "41", "b" "98", "c" "8", "d" "34"}
; {"a" "341", "b" "125", "c" "3", "d" "19"}
; {"a" "65", "b" "23", "c" "8", "d" "70"})
The cake is a lie.
The cake is a lie.
The cake is a lie.
|