From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA17991; Wed, 17 Mar 2004 14:00:52 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA17751 for ; Wed, 17 Mar 2004 14:00:51 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from tnetsmtp1.mail.isp (stress.telefonica.net [213.4.129.135]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i2HD1HKW021414 for ; Wed, 17 Mar 2004 14:01:18 +0100 Received: from [172.26.0.2] ([217.127.9.243]) by tnetsmtp1.mail.isp (terra.es) with ESMTP id HUOS0D00.4OC for ; Tue, 16 Mar 2004 21:38:37 +0100 Mime-Version: 1.0 (Apple Message framework v612) Content-Transfer-Encoding: quoted-printable Message-Id: Content-Type: text/plain; charset=ISO-8859-1; format=flowed To: caml-list@pauillac.inria.fr From: =?ISO-8859-1?Q?Agust=EDn_Valverde?= Subject: [Caml-list] Better option to read a file Date: Tue, 16 Mar 2004 21:38:34 +0100 X-Mailer: Apple Mail (2.612) X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; agust:01 ctima:01 char:01 char:01 agust:01 spain:99 rec:01 parser:02 parser:02 arch:02 arch:02 string:03 string:03 data:03 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 153 Hi In a program I need to read the input data from a file and I have=20 written several options. I want to obtain the string of characters from=20= a text file and I don't know what is the better option. Among others, I=20= have written the following: First option: let leer_file fl =3D let form =3D ref "" in let arch =3D open_in fl in let long =3D in_channel_length arch in form :=3D String.create (long-1); really_input arch (!form) 0 (long-1); close_in arch; !form;; Second: let rec unir c ac =3D unir ac^(Char.escaped c);; let leer2 fl =3D let form =3D ref "" in let c =3D ref '-' in let arch =3D open_in fl in (try (while true do (c :=3D input_char arch); (if !c !=3D '\n' then = (form=20 :=3D 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=20 functions merging them with the parser in some way? Thanks for your help Agust=EDn 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