> < ^ Date: Tue, 18 Apr 2000 11:40:32 +0100
> < ^ From: Steve Linton <sal@dcs.st-and.ac.uk >
> < ^ Subject: Re: file operations

Dear GAP Forum,

Enis Karaaslan asked:

I have a file which consists of random numbers
- consisting of only number streams and I want to read it and use it.
I couldnt do that with the basic file operations.

If you want to read files into GAP which are not written in the GAP input
syntax, you need to use streams, which are documented in chapter 10 of the
reference manual. This will let you read the file byte-by-byte or line-by-line
and you can then use a GAP program to extract the numbers you need.

For example, if your file is called numbers and contains integers, one per
line, with no extra space, then something like the following should work.

s := InputTextFile("numbers");
numbers := [];
while not IsEndOfStream(s) do
  l := ReadLine(s);
  if l = fail then 
	break;
  fi;
  l := l{[1..Length(l)-1]}; # strip newline
  Add(numbers, Int(l));	
od;

Steve Linton


> < [top]