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.


In reply to Re: Convert array to array of hashes by Fletch
in thread Convert array to array of hashes by snra_perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.