English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-01-26 (15:50)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] read file
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

Use Unix-module only, if you need it (e.g. reading from pipes or such stuff).