On 7/7/05, wolverian <[EMAIL PROTECTED]> wrote: > On Thu, Jul 07, 2005 at 08:18:40PM +0300, wolverian wrote: > > I'm a pretty high level guy, so I don't know about the performance > > implications of that. Maybe we want to keep seek() low level, anyway. > > Sorry about replying to myself, but I want to ask a further question on > this. > > Would it be possible to make this work, efficiently: > > for =$fh[-10 ...] -> $line { ... } > > to iterate over the last ten lines?
No. Most notably because -10 ... gives (-10, -9, ... -1, 0, 1, 2, 3, ...). I also don't think that without a special interface filehandles can behave as an array of lines. If they could, then you'd have: for $fh[-10..-1] -> $line {...} > Can we generalise that to be as performance-effective as seek()? Perhaps. That's what tail(1) does. But it's a tricky problem. You have to guess where the end should be, then do a binary search on the number of lines after your position. Sounds like a job for a specialized module to me. If you don't care about speed, then I suppose you could even do: for [ =$fh ].[-10..-1] -> $line {...} Which won't be speed efficient, and may or may not be memory efficient, depending on the implementation. I'd guess not. Luke