# Re: (libruby) reading a file line by line

**URL:** <https://www.ruby-forum.com/t/re-libruby-reading-a-file-line-by-line/95256>\
**Category:** Ruby\
**Created:** [May 25, 2006, 7:43pm UTC](https://www.ruby-forum.com/t/re-libruby-reading-a-file-line-by-line/95256 "2006-05-25T19:43:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zbrod](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/278dde/32.png) [@zbrod](https://www.ruby-forum.com/u/zbrod)\
**Post date:** [May 25, 2006, 7:43pm UTC](https://www.ruby-forum.com/t/re-libruby-reading-a-file-line-by-line/95256/1 "2006-05-25T19:43:59Z")

</div>

Prehaps something like this

f = File.open(“inventory”)  
f.each do |hostName|  
hostName.chomp!  
end

---

<div class="post-metadata">

**Author:** ![zbrod](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/278dde/32.png) [@zbrod](https://www.ruby-forum.com/u/zbrod)\
**Post date:** [May 25, 2006, 9:41pm UTC](https://www.ruby-forum.com/t/re-libruby-reading-a-file-line-by-line/95256/2 "2006-05-25T21:41:11Z")

</div>

Hi,

On Fri, May 26, 2006 at 02:41:13 +0900, Zach B. wrote:

[top post fixed]

> > Basically what I would like to do is read a file in line by line chomping  
> > the line on the way. It’s easy enough in c but I would like to do it  
> > using the functionality from libruby.

> > I’ve go the file object using rb\_file\_open(), can someone suggest how I  
> > might use each\_line to do what I want to?
> 
> Prehaps something like this
> 
> f = File.open(“inventory”)  
> f.each do |hostName|  
> hostName.chomp!  
> end

Thanks for the answer but I may have been un-clear. I’m wanting to do  
this  
from a c program using libruby.

Cheers,  
Phil
