Re: File input.output
- Posted by bobspringett <bobspringett at WANADOO.FR> Aug 29, 2000
- 500 views
Irv, Had a further look at your suggestions. Couldn't quite understand the purpose of the line numbers=numbers[2]. Seems as though your saying the sequence numbers is now = the second item in numbers. A further point. I've made up a short code along the lines of your suggestion and a strange thing is happening. The codes generates some floating point data which round limits to 2 decimal places, it saves O.K and gives a length of 10. However when I load the data into the sequence testData and print it a further couple of braces has slipped in and the length is now two. I've omitted the round function and I still get the same thing happening. Would you mind commenting on it for me please. CODE: --include misc.e include file.e include get.e include print.e include round.e with trace --trace(1) sequence y atom x y={} atom filenum sequence testData for i=1 to 10 do x=rand(999)+i/9 x=round(x,2) y=y & x end for filenum=open("c:\\euphoria\\tester.txt","w") print(filenum,y) close(filenum) print(1,"Finished filing") print(1,y) sleep(10) print(1," ") filenum=open("c:\\euphoria\\tester.txt","r") testData=get(filenum) close(filenum) print(1,testData) print(1,"Finished loading and displaying") sleep(10) ----- Original Message ----- From: irv <irv at ELLIJAY.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Sunday, August 27, 2000 9:42 PM Subject: Re: File input.output > On Sun, 27 Aug 2000, BOB wrote: > > I would like to be able to SAVE a sequence of floating point numbers(say a > > few hundred) to a file in one PUTS and then retrieve > > that data from file back into a sequence in one GETS. > > Looking at the documentation of GETS it would seem that I can't. > > Secondly will I be able to look at what's in the file using Explorer to see > > if I have filed the right information. > > Really all I'm trying to do is to SAVE and LOAD a 'sequential file' > > reasonably quickly. > > Regards > > It looks like you've gotten several answers, but based on your requirements, > I also to suggest using print() and get(). It's quick and easy, and hard ato > break. > > -- tested code: > include get.e > object numbers > numbers = {1.23, 3.14159, 6, 8, -23.5, 12.99} > > atom fn > fn = open("my.dat","w") > print(fn, numbers) > close(fn) > > fn = open("my.dat","r") > numbers = get(fn) > close(fn) > if numbers[1] = GET_SUCCESS then > numbers = numbers[2] > else > puts(1,"ERROR READING FILE") > end if > ? numbers > > If you plan to store lots of strings in your files, you really need to > downloading Gabriel Boehme's PRINT.E - this small library causes the print() > function to write text in plain, human readable form, while still being > readable by Euphoria's get() function. > > I have been using this method for many months in several commercial programs > without any problems These programs typically read (modify) and write files > of > about half a meg hundreds of times each day. > > By the way, these files will be plain text, so probably NotePad or similar > would be just fine for viewing them. > > Regards, > Irv