Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Better option to read a file
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Agustín_Valverde <a_valverde@c...>
Subject: [Caml-list] Better option to read a file

In a program  I need to read the input data from a file and I have 
written several options. I want to obtain the string of characters from 
a text file and I don't know what is the better option. Among others, I 
have written the following:

First option:

let leer_file fl =
      let form = ref "" in
      let arch = open_in fl in
      let long = in_channel_length arch in
      form := String.create (long-1);
      really_input arch (!form) 0 (long-1);
      close_in arch;


let rec unir c ac = unir ac^(Char.escaped c);;

let leer2 fl =
      let form = ref "" in
      let c = ref '-' in
      let arch = open_in fl in
        (while true do (c := input_char arch); (if !c != '\n' then (form 
:= unir !c !form) else ()) done)
      with End_of_file -> close_in arch);

I also have a parser to convert the string, could I to improve these 
functions merging them with the parser in some way?

Thanks for your help

Agustín Valverde
Department of Applied Mathematics
University of Malaga, Spain
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: