From: Paul Brannan [mailto:email@example.com]
I have an implementation of tail -f that looks similar, except it
doesn’t seek to the end of file at start
I guess to truly imitate the *nix tail -f command, it should read the 10
last lines and then start its wait cycle. Should it be that faithful?
, and it’s called like this:
File.open(filename) do |input|
tail_f(input) do |line|
Two advantages here:
- If an exception is raised from inside the block, the file will be
- I get my input line-by-line, which imo is much more useful than
Regarding the file closure, I think I was relying on scope to kill it. I
wasn’t really sure how egregious it was to not politely close a file. In
Perl, it’s recommended but not required.
As for the input method, I think I like your line by line approach better.
I used the buffersize approach because, well, that’s how the Perl module did
Some advantages of your implementation:
- It is an object, and acts somewhat like an IO object, thus
- If RCR#65 (http://www.rubygarden.org/article.php?sid=179) were
accepted, it could easily be modified to inherit from IO and make
this class act just like a pipe.
I read the RCR. I think it’s a good idea, though it also sounds like quite
a bit of work. Any idea on the status of this? Sounds like a good topic
for a Ruby gathering.
- The sleep interval and buffer size are adjustable.
offset = io.tell
line = input.gets
yield line if not line.nil?
if input.eof? then
Nice. I’m gonna work on this some today, so I’ll see if perhaps I
can/should use this approach instead.