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 EAA25637; Wed, 17 Mar 2004 04:45:42 +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 EAA25961 for ; Wed, 17 Mar 2004 04:45:40 +0100 (MET) Received: from mail.rsise.anu.edu.au (mail.rsise.anu.edu.au [150.203.208.4]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i2H3k5KW002384 for ; Wed, 17 Mar 2004 04:46:06 +0100 Received: from localhost (localhost [127.0.0.1]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id A10E614D3 for ; Wed, 17 Mar 2004 14:45:08 +1100 (EST) Received: from pulp.anu.edu.au (pulp.anu.edu.au [150.203.126.25]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id 257FC14D2 for ; Wed, 17 Mar 2004 14:45:07 +1100 (EST) Received: by pulp.anu.edu.au (Postfix, from userid 1560) id AB86BC086F; Wed, 17 Mar 2004 14:48:07 +1100 (EST) Date: Wed, 17 Mar 2004 14:48:07 +1100 From: Pietro Abate To: caml-list@inria.fr Subject: Re: [Caml-list] Better option to read a file Message-ID: <20040317034807.GA25205@pulp.anu.edu.au> Mail-Followup-To: Pietro Abate , caml-list@inria.fr References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: GNU/Linux X-Organization: Research School of Information Science and Engineering (Australian National University) User-Agent: Mutt/1.5.5.1+cvs20040105i X-Scanned-By: AMaViS-ng/Claimv at mail.rsise.anu.edu.au 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; pietro:01 abate:01 pietro:01 abate:01 caml-list:01 2004:99 agust:01 char:01 char:01 agust:01 spain:99 bug:01 faq:01 faq:01 beginner's:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 148 what's about .... let file_ch = (open_in input_file) in let read_lines = let read_new_line n = try Some (input_line file_ch) with End_of_file -> None in Stream.from read_new_line in let rec get_line () = match Stream.next read_lines with |s when Str.string_match (Str.regexp "^[\n\t ]+$") s 0 -> get_line () |s -> s in p On Tue, Mar 16, 2004 at 10:28:37PM +0100, Agust?n Valverde wrote: > 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 -- ++ If you have an apple and I have an apple and we exchange apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas. -- George Bernard Shaw ++ Please avoid sending me Word or PowerPoint attachments. See http://www.fsf.org/philosophy/no-word-attachments.html ------------------- 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