[Haskell-cafe] How to deal with huge text file?

Daniel Fischer daniel.is.fischer at web.de
Tue May 25 04:19:07 EDT 2010


On Tuesday 25 May 2010 08:14:13, Ivan Miljenovic wrote:
> On 25 May 2010 16:12, Magicloud Magiclouds
>
> <magicloud.magiclouds at gmail.com> wrote:
> > Yes, this code works with a little hack. Thank you.
>
> I'm scared to ask: what pray tell is this little hack?

Looking at it again, probably making it work at all, because I never 
consumed the "Log for " lines, so produced an infinite list of empty lists 
:-/

Something like

separateOutput :: String -> [[String]]
separateOutput file =
    let contents = dropWhile (not . ("Log for " `isPrefixOf`)) $ lines file
        split [] = ([],[])
        split (h:tl) = let (lg,rst) = break ("Log for " `isPrefixOf`) tl 
                       in (h:lg,rst)
        msplit [] = Nothing
        msplit lns = Just (split lns)
    in unfoldr msplit contents

which really works :)


More information about the Haskell-Cafe mailing list