Re: how get "number" in disk text file read into integer variable?

new topic     » topic index » view thread      » older message » newer message

Irv,

Oh.

So if I SAVE a structured variable to file with "print", and READ with
"get", I can USE numeric values I stored in the file, fairly directly; sorta
like it says in the Euphoria documentation:

"The combination of print() and get() can be used to save a Euphoria object
to disk and later read it back. This technique could be used to implement a
database as one or more large Euphoria sequences stored in disk files. "

What this REALLY says to me is that we (or at least *I*) could well benefit
from a EUPHORIA FAQ. ('course, that would mean I would have to READ it,
instead of just throwing out questions to the list members, but that's a
different matter :)

I modified your example to see if I might be able to use it; mod is below.

Thanks.

Dan Moyer

-- modified code:

include get.e

integer fn, dummy
object fontin
sequence fontout

fontout = {1,2,3.1415,100,"SomeTextHere"} -- example data in variable

-- write the data (to two lines)
fn = open("Font.dat","w")
print(fn,fontout ) -- fontout[1..4] if you want to save only part
puts(fn,"\n")-- line feed
print(fn,fontout)-- writes a 2nd line also
close(fn)

-- read the data
fn = open("Font.dat","r")
fontin = get(fn)
close(fn)
fontin = fontin[2] -- discard the disk read success flag

for n = 1 to 4 do -- to see the numbers stored in the variable
print(1,fontin[n])
puts(1,"\n") -- make new line
end for
puts(1,fontin[5])-- to see the text stored in the variable
puts(1,"\n")
puts(1,"\n")

if fontin[4] = 100 then -- test to see if retrieved "number" is useable
  puts(1,"yes! the retrieved number is useable as an number in program")
end if
  puts(1,"\n")
puts(1,"\n")

puts(1,"(press any key to exit)")
dummy = wait_key()  -- lets it stay on screen until key pressed

-- mod ends

-----Original Message-----



>From: Dan B Moyer <DANMOYER at PRODIGY.NET>
>
>Subject: Re: how get "number" in disk text file read into integer variable?
>
>
>> Ok Irv,
>>
>> If you're suggesting that I may not have needed to do the integer-to-byte
>&
>> back again translation, I suspect you're probably right.
>
>This stems from the fact that Euphoria has so many ways to input and output
>data. It gets confusing as to which is the proper or best to use in a given
>circumstance. Here's one way to do what you want:
>
>include get.e
>integer fn, y
>object fontin
>sequence fontout
> fontout = {1,2,3.1415,6,"Fillmore"}
>
>-- write part of the data
>fn = open("Font.dat","w")
>print(fn,fontout) -- fontout[1..4] if you want to save only part
>close(fn)
>
>-- read the data
>fn = open("Font.dat","r")
>fontin = get(fn)
>close(fn)
>fontin = fontin[2] -- discard the disk read success flag
>
>y = fontin[2]
>print(1,y)

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu