From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 9BE42BB91 for ; Wed, 26 Jan 2005 16:50:18 +0100 (CET) Received: from first.in-berlin.de (dialin-145-254-054-108.arcor-ip.net [145.254.54.108]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0QFoHn5023314 for ; Wed, 26 Jan 2005 16:50:17 +0100 Received: by first.in-berlin.de (Postfix, from userid 501) id 78B6AA3E91; Wed, 26 Jan 2005 16:50:13 +0100 (CET) Date: Wed, 26 Jan 2005 16:50:13 +0100 From: Oliver Bandel To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] read file Message-ID: <20050126155013.GA320@first.in-berlin.de> References: <1106691570.41f6c5f250fdc@www.doc.ic.ac.uk> <41F6CB7B.7050406@1969.ws> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6i X-Miltered: at nez-perce with ID 41F7BC39.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; oliver:01 bandel:01 oliver:01 in-berlin:01 caml-list:01 wrote:01 ocaml's:01 appending:01 ocamllex:01 unix-module:01 unix-module:01 26,:98 daisy:98 strings:01 functions:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.0 X-Spam-Level: On Wed, Jan 26, 2005 at 02:41:41PM +0000, Yan Jun Daisy Chen wrote: > I am trying to extract all the > comments i.e. all the text between (* and *) in a text file and store > them in a list of string. How do u determin the length of the file? The length of the file? Not necessary to know. Or are the comments maybe as long as the file itself? You better do using OCaml's built-in operations for reading files. Look for open_in, read_line and so forth. You also can use the Buffer-module to be much faster, when appending strings together to a bigger string. You can do such scanning with ocamllex. But it's also possible to write your own scanner. Do not use Unix-module for that stuff. It's portable to use the built-in functions open_in and such stuff (like read_line and so forts), or the Buffer-module. Use Unix-module only, if you need it (e.g. reading from pipes or such stuff). Ciao, Oliver