From: Xavier Noria on 22 Jul 2010 10:33 Check the elif gem, by James Edward Gray II. It is a port of File::ReadBackwards, whose documentation explains the approach: http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm#DESIGN -- fxn
From: Urabe Shyouhei on 22 Jul 2010 11:36 (2010/07/22 23:33), Xavier Noria wrote: > Check the elif gem, by James Edward Gray II. > > It is a port of File::ReadBackwards, whose documentation explains the approach: > > http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm#DESIGN And says nothing about multiligualization because M17N cannot be achieved by the approach, theoretically. Maybe that's OK for Ted. I'm living in a different world than you perhaps.
From: James Edward Gray II on 22 Jul 2010 11:42 On Jul 22, 2010, at 10:36 AM, Urabe Shyouhei wrote: > (2010/07/22 23:33), Xavier Noria wrote: >> Check the elif gem, by James Edward Gray II. >> >> It is a port of File::ReadBackwards, whose documentation explains the approach: >> >> http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm#DESIGN > > And says nothing about multiligualization because M17N cannot be achieved by the approach, theoretically. Yes, I wrote it before Ruby 1.9's m17n engine. I only use it on ASCII logs, where it works fine. I would not recommend it for encoded data. James Edward Gray II
From: Xavier Noria on 22 Jul 2010 12:04 On Thu, Jul 22, 2010 at 5:36 PM, Urabe Shyouhei <shyouhei(a)ruby-lang.org> wrote: > And says nothing about multiligualization because M17N cannot be achieved by > the approach, theoretically. So in general you can't detect character boundaries going backwards? You can always have cut characters and still have a valid buffer?
From: Robert Klemme on 22 Jul 2010 14:04 On 22.07.2010 16:22, Urabe Shyouhei wrote: > (2010/07/22 22:06), Robert Klemme wrote: >>> Then how about: >>> >>> File.open(f).each_line.inject(nil){|x,y|y} >>> >>> Slower than my first answer though. >> A solution that is efficient for large files will >> use File#seek to move position to the end of the file and go backwards >> from there. > > No, that can't work -- or that works only when you are sticking on the ASCII > character set. Multibyte encodings are not safe to read backwards > (sometimes). The only safe way is to read the whole content from the > beginning, at least one time. Good point. Although pragmatically for fixed width and UTF-8 encoded files it will work and the performance gains for large files are significant enough to warrant this approach. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
First
|
Prev
|
Pages: 1 2 3 Prev: Enumerators and generators Next: functions to escape and unescape strings in rails |