Hi Cliff,

There are at least 2 approaches you can try:

1. Use an atom to store the fields data, updating it whenever you encounter 
a #Fields row, and referencing it when processing data rows.

2. Use (reduce) to process the rows, using the accumulator to store both 
the current count and fields data.  Something like this:

(reduce (fn [{:keys [count fields] :as acc} row]
          ;; the above de-structuring makes current count and fields 
available
          (cond
           ;; if it's a fields row...
           (fields-row? row) (let [new-fields :compute-new-fields-here]
                               (assoc acc :fields new-fields))
           ;; if it's a data row...
           (data-row? row) (let [new-count :compute-new-count-here]
                             (assoc acc :count new-count))))
        {:count 0 :fields []}
        rows)

I think both approaches are equally valid, it's just a matter of which one 
appeals to you more.  Hope this helps!

On Thursday, April 12, 2012 9:38:31 AM UTC-7, Cliff Mosley wrote:
>
> Prefacing this with being a complete Clojure novice, my question is more 
> about approach than the actual code required. Like many, I have a few tried 
> and true examples that I like to work through in each language. In my case, 
> I have a set of IIS log files that I want to generate usage statistics on. 
> The hitch in my particular problem is that the log files may or may not 
> have columns redefined within the file.
>
> As an example 
> #Software: Microsoft Internet Information Services 6.0
> #Version: 1.0
> #Date: 2011-05-02 17:42:15
> #Software: Microsoft Internet Information Services 6.0
> #Version: 1.0
> #Date: 2011-05-02 17:42:15
> #Fields: date time c-ip cs-username s-ip s-port cs-method cs-uri-stem 
> cs-uri-query sc-status cs(User-Agent)
> 2011-05-02 17:42:15 172.22.255.255 - 172.30.255.255 80 GET 
> /images/picture2.jpg - 200 
> Mozilla/4.0+(compatible;MSIE+5.5;+Windows+2000+Server)
> 2011-05-02 17:43:15 172.22.255.255 - 172.30.255.255 80 GET 
> /images/picture1.jpg - 200 
> Mozilla/4.0+(compatible;MSIE+5.5;+Windows+2000+Server)
> .
> .
> <many more lines>
> .
> .
> #Same file, s-ip is now removed so ordinal positions are changed
> #Fields: date time c-ip cs-username s-port cs-method cs-uri-stem 
> cs-uri-query sc-status cs(User-Agent)
> 2011-05-02 17:48:15 172.22.255.255 - 80 GET /images/picture1.jpg - 200 
> Mozilla/4.0+(compatible;MSIE+5.5;+Windows+2000+Server)
> 2011-05-02 17:49:15 172.22.255.255 - 80 GET /images/picture3.jpg - 200 
> Mozilla/4.0+(compatible;MSIE+5.5;+Windows+2000+Server)
>
> So with the above data, I am trying to get the count of log file hits from 
> a given cs(User-Agent). In other languages, I would just read in the 
> #Fields row and continue processing merrily given the most recent order I 
> encountered moving through the file sequentially. With Clojure, the 
> immutability of the fields is throwing a wrench for me.
>
> If anyone could give me a nudge in the right direction, I would appreciate 
> it.
> Cliff
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to