Re: Help: Getting Sequences from Files

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

D. Brent O'Gara wrote:
> 
> I'm trying to learn some (very) basic programming in Euphoria, and I can't
> seem to get my sequences back from the files I write them to.
> 
> example:
> <eu code>
> 
> include get.e
> 
> integer FN
> sequence stuff
> 
> stuff = {{"a","b"},{"c","d"}}
> 
> ? stuff
> puts(1, "\n")
> 
> FN = open("D:\\euphoria\\test\\test.wb", "wb")
> print(FN, stuff)
> close(FN)
> 
> FN = open("D:\\euphoria\\test\\test.wb", "rb")
> stuff = get_bytes(FN, 100)
> 
> ? stuff
> puts(1, "\n")
> 
> FN = open("D:\\euphoria\\test\\test.wb", "rb")
> stuff = gets(FN)
> 
> ? stuff
> 
> </eu  code>
> 
> I used all the '?' to see what 'stuff' was looking like at each step of the
> process.  I tried changing from "wb" to just "w" but it didn't seem to do
> anything different.  I also changed the "rb" 's to "r" 's, but again, I got
> the same results both ways.
> 
> I'd really like to be able to get 'stuff' to come back as
> '{{"a","b"},{"c","d"}}'  even '{{{97},{98}},{{99},{100}}}' would work.  When
> I read the file back into the sequence I get
> '{123,123,123,57,55,125,44,123,57,56,125,125,44,123,123,57,57,125,44,123,49,
> 48,48,125,125,125}' which does not help me at all.  I recognise that it has
> simply changed the '{' into '123' etc, but I don't know how to get it back.
> 
> I'm looking for a way to send a sequence of sequences out to a file, and
> then later retrieve the sequence of sequences in the same format that I
> originally sent it out in.
> Additionally, how do I get it to display '{{{97},{98}},{{99},{100}}}' as
> '{{"a","b"},{"c","d"}}' onscreen? (I only need one letter at a time, and
> It's just an example sequence, so how do I get it to print 'stuff[1][2]' as
> 'b' and not '98'?)
> 
> Thanks for any help anyone can give me.  The last time I had to write a
> working program was in middle school using apple basic on an apple 2e.  So
> I'm feeling kinda overwhelmed.  I recognize most of what Euphoria is capable
> of doing, but I can't seem to figure out which commands do it.
> 
> what I'm attempting to accomplish with this is to be able to take several
> 256color bitmaps with the same pallette, and turn them into 1 file which
> contains a sequence 'x', where 'x[1]' is the first image, 'x[2]' is the
> second image, and so on, while the pallette is in another file altogether.
> 
> Thank-you all!
> 
>     -Brent O'
> 
> 
include get.e
--------------save a whole file as a sequence --------
global procedure save(sequence fileName,sequence data)
  object fn
  fn=open(fileName,"w")
  print(fn,data)
  close(fn)
end procedure

--------------load a whole euphoriia file as a sequence----
global function load(sequence fileName)
  object fn, seq
  fn=open(fileName,"r")
  seq=get(fn)
  if atom(seq) then
      puts(1,"can't read file"&fileName)
   end if
  seq=seq[2]
  close(fn)
  return seq
end function

------------much faster--------------
--I use  Binary Print/Get by Gabriel Boehme (availabe in the archives).

include bget.e

------------------the binary way --------------------
--------------load a whole euphoriia file as a sequence----
global function get_file(sequence file_name)--binary file
     integer fn
     object database
      fn = open(file_name, "rb")
       if fn=-1 then 
         puts(1,"Can't open file:"& file_name)
       end if
      database = bget(fn)
      close(fn)
     if length(database)<2 then
        return {}
       else
        return database[2]
     end if
end function

--------------save a whole file as a sequence --------
global procedure save_file(sequence db,sequence file_name)
    integer fn
    fn = open(file_name, "wb")
     bprint(fn,db)
    close(fn)
end procedure

That.s what I use,
don cole
 S.F.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu