parsing a file line by line
Hal Daume III
hdaume at ISI.EDU
Thu Oct 16 13:57:02 EDT 2003
Take a look at the functions lines and words.
On 16 Oct 2003, Anagha wrote:
> Hi ,
I am a new bie to haskell.
I need to read a file and get it contents line by line and then eventually word by word.
I have written the code to read a file , but the returned value is all the lines in the file.
How do I parse this whole text message ( contents of the file) into individual lines ( that is parsing / splitting the whole text to get me one line at a time.
Also once I get the individual line, I o parse it word by word.
I have a start on this thing. by using the line function in haskell, but I have not managed to write it successfully.
Can anyone help me in this.
Below is the code to read a file.
fileFun :: IO ()
fileFun = do
putStr "Please input a file name: "
fname <- getLine
contents <- readFile fname
How do I split the data returned in contents( Contents contains all the text in the file, which is given as input)
Thanks
Anagha
--
Hal Daume III | hdaume at isi.edu
"Arrest this man, he talks in maths." | www.isi.edu/~hdaume
More information about the Haskell-Cafe
mailing list