Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3664

Re: File position and buffers

From 7stud -- <bbxx789_05ss@yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: File position and buffers
Date 2011-04-28 18:31 -0500
Organization Service de news de lacave.net
Message-ID <c73bca63732c4f7e0943455cdc55a935@ruby-forum.com> (permalink)
References <10d8ae57765e21626a7c64873dcba807@ruby-forum.com> <97869b15e6f881b951b4b230011182e0@ruby-forum.com> <a8bfb33ef4ce932d8afc29b01bb29252@ruby-forum.com>

Show all headers | View raw


Cee Joe wrote in post #995597:
>
> my mentor wants me to use the IO.pos to read the
> characters of the file until the character reaches the ">" symbol.
>

IO.pos() does not read in data, so you are going to have to ask your 
mentor what he means.   You should also ask your mentor if this is a 
lesson in how not to do things.  If he doesn't reply in the affirmative, 
then you should find a new mentor.


> I am extracting text from each entry I read in, something I have figured
> out already. I want to read the file line by line and just store each
> entry into a buffer when it reaches the ">" symbol. THen extract
> specific info from it later.
>

You told us you were not supposed to read the whole file into memory. 
If you store every line in an array, then you will have read the whole 
file into memory.  Once again, you are not being clear on what you want 
to do with the data.  You need to tell us which of the following you 
want to do:

1) Store every entry in an array, and "extract specific info from it 
later".

2) Read one entry, do something to the entry, then discard it and read 
in the next entry.


> The entry lengths all vary as there long
> and short lengths. File is in text mode.
>

Ok.

>> What problems is that giving you?  You can create a loop, read the
>> character at pos(i), then increment i, and do what Jesús Gabriel y Galán
>> suggested.
>

You could use each_byte to read the file char by char (that assumes your 
file contains all ascii characters), then when you find a '>', seek() 
back to the start of the file, and use IO.sysread() to read:

 old_pos = 0
 pos() - old_pos

number of characters.  Then do something like:

old_pos = pos()

and keep doing that. But, you will be reading every entry twice, which 
is stupid.

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

File position and buffers Cee Joe <cyril_jose@ymail.com> - 2011-04-27 15:02 -0500
  Re: File position and buffers Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-27 16:47 -0500
  Re: File position and buffers jake kaiden <jakekaiden@yahoo.com> - 2011-04-27 17:33 -0500
  Re: File position and buffers 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-27 19:08 -0500
  Re: File position and buffers 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-27 19:50 -0500
  Re: File position and buffers Robert Klemme <shortcutter@googlemail.com> - 2011-04-28 02:54 -0500
    Re: File position and buffers 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-28 13:06 -0500
      Re: File position and buffers 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-28 13:25 -0500
        Re: File position and buffers Cee Joe <cyril_jose@ymail.com> - 2011-04-28 13:29 -0500
  Re: File position and buffers Cee Joe <cyril_jose@ymail.com> - 2011-04-28 09:06 -0500
  Re: File position and buffers 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-28 12:47 -0500
    Re: File position and buffers Cee Joe <cyril_jose@ymail.com> - 2011-04-28 13:27 -0500
      Re: File position and buffers 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-28 18:31 -0500
        Re: File position and buffers Cee Joe <cyril_jose@ymail.com> - 2011-04-28 20:05 -0500
  Re: File position and buffers 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-28 21:58 -0500
    Re: File position and buffers Cee Joe <cyril_jose@ymail.com> - 2011-04-29 10:20 -0500
  Re: File position and buffers jake kaiden <jakekaiden@yahoo.com> - 2011-04-28 22:36 -0500
  Re: File position and buffers 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-29 12:50 -0500
    Re: File position and buffers Cee Joe <cyril_jose@ymail.com> - 2011-04-29 13:32 -0500
      Re: File position and buffers 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-29 17:45 -0500
  Re: File position and buffers jake kaiden <jakekaiden@yahoo.com> - 2011-04-29 15:38 -0500
  Re: File position and buffers Cee Joe <cyril_jose@ymail.com> - 2011-04-29 16:10 -0500

csiph-web