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 EAA25136; Wed, 17 Mar 2004 04:37:16 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA23639 for ; Wed, 17 Mar 2004 04:37:13 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from telesmtp3.mail.isp (imap.telefonica.net [213.4.129.150]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i2H3bCHd025041 for ; Wed, 17 Mar 2004 04:37:13 +0100 Received: from [172.26.0.2] ([217.127.9.243]) by telesmtp3.mail.isp (terra.es) with ESMTP id HUOUBS00.717; Tue, 16 Mar 2004 22:28:40 +0100 Mime-Version: 1.0 (Apple Message framework v612) Content-Type: text/plain; charset=ISO-8859-1; format=flowed Message-Id: Content-Transfer-Encoding: quoted-printable From: =?ISO-8859-1?Q?Agust=EDn_Valverde?= Subject: [Caml-list] Better option to read a file Date: Tue, 16 Mar 2004 22:28:37 +0100 To: caml-list@inria.fr X-Mailer: Apple Mail (2.612) X-Miltered: at concorde 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: 147 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