in reply to Re^2: file size limit with Tie::File
in thread file size limit with Tie::File

I am trying to display a 1000 lines or so at a time in a Tk ROText widget and I thought this tie could work. I'll go back to while ( <FH> ) and tells and seeks and see if that gives me better performance.

You might find some relevant ideas in this older thread: Displaying/buffering huge text files.

If you decide to take the time to index the byte offsets to all the line-endings in your log file, that will surely end up providing much better performance, but if the log file changes over time, you'll be updating the index constantly. Of course, that'll be a simple process of appending more byte offsets as more lines are added, but it's likely that the index will become unwieldy (maybe the line count is such that indexing all the lines is already unwieldy).

If the goal is simply to be able to show a good-sized chunk of lines in a Tk ROText window, maybe you don't really need accurate info about where the line endings are. Just use reasonable estimates where necessary, along the following lines:

$requested_start = ...; # a value between 0 and 1 $avg_line_len = ...; # make a guess or read a small sample to est +imate this $file_size = -s $filename; $read_length = $avg_line_len * 1000; seek( FH, $file_size * $requested_start, 0 ); read( FH, $text, $read_length ); $text =~ s/^.*\n//; # trim initial and final $text =~ s/.*$//; # line fragments from $text