caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Better option to read a file
@ 2004-03-16 20:38 Agustín Valverde
  0 siblings, 0 replies; 10+ messages in thread
From: Agustín Valverde @ 2004-03-16 20:38 UTC (permalink / raw)
  To: caml-list

Hi

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;
      !form;;

Second:

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
      (try
        (while true do (c := input_char arch); (if !c != '\n' then (form 
:= unir !c !form) else ()) done)
      with End_of_file -> close_in arch);
      !form;;

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 caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 10+ messages in thread
* [Caml-list] Better option to read a file
@ 2004-03-16 21:28 Agustín Valverde
  2004-03-17  3:48 ` Pietro Abate
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Agustín Valverde @ 2004-03-16 21:28 UTC (permalink / raw)
  To: caml-list

Hi

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;
      !form;;

Second:

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
      (try
        (while true do (c := input_char arch); (if !c != '\n' then (form 
:= unir !c !form) else ()) done)
      with End_of_file -> close_in arch);
      !form;;

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 caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-03-17 18:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-16 20:38 [Caml-list] Better option to read a file Agustín Valverde
2004-03-16 21:28 Agustín Valverde
2004-03-17  3:48 ` Pietro Abate
2004-03-17  7:31 ` Christoph Bauer
2004-03-17 16:42   ` Agustin Valverde Ramos
2004-03-17 17:46     ` Markus Mottl
2004-03-17 18:20       ` Agustin Valverde Ramos
2004-03-17 18:54         ` Markus Mottl
2004-03-17  8:22 ` Jean-Christophe Filliatre
2004-03-17 10:11   ` Markus Mottl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).