Newsgroups: fa.haskell
From: Pete Kazmier <pete-expires-20060...@kazmier.com>
Date: Sun, 01 Oct 2006 18:55:40 UTC
Local: Sun, Oct 1 2006 2:55 pm
Subject: [Haskell-cafe] How would you replace a field in a CSV file?
The other day at work an opportunity arose where I was hoping to sneak
some Haskell into the pipeline of tools used to process call detail records (CDRs). In the telecommunications industry, CDRs are used for billing. Each CDR is a single line record of 30 comma-separated values. Each line is approximately 240 characters in length. The task at hand is to replace field number 10 if a new value can be found in a hashmap which is keyed using the contents of the field. My colleague was going to write a C program (that's all he knows), but For those that know python, here is a very simple implementation that for line in sys.stdin: For each line in standard input: - Splits the string on the comma: "field0,field1,...,field29" => - Gets the value associated with the key of field9 from tgmap, if it - Joins the list of fields with a comma to yield a string again Here is my first Haskell attempt: import Data.ByteString.Lazy.Char8 as B hiding (map,foldr) -- This is just a placeholder until I actually populate the map main = B.interact $ B.unlines . map doline . B.lines -- f is supplied the index of the current element being processed After talking with dons on #haskell, he cleaned my version up and import Data.ByteString.Lazy.Char8 as B hiding (map,foldr) -- This will be populated from a file main = B.interact $ B.unlines . map doline . B.lines -- f is supplied the index of the current element being processed That helped things a bit, but I must confess I don't understand how And then he came up with another version to avoid the 'unlines', but Thanks, _______________________________________________ You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||