my $max_lines = 100; open(my $fh, '<', $path) or die("Unable to open file $path: $!\n"); my $line = $cgi->param('line') || 0; my $pos = $cgi->param('pos'); if (defined($pos)) { seek($fh, $pos, 0) or die("Unable to seek to $pos: $!\n"); } else { if ($line) { do { <$fh> } while $. < $line; } } my $lines = $max_lines; print(qq{
\n}); while ($lines-- && defined(my $line = <$fh>)) { chomp($line); print(html_escape($line), qq{
\n}); } print(qq{
\n}); my $first = ($line == 0); my $last = not defined(<$fh>); my $prev_line = $line - $max_lines; $prev_line = 0 if $prev_line < 0; my $prev = "?line=$prev_line"; my $next_line = $line + ($max_lines - $lines) - 1; my $next_pos = tell($fh); my $next = "?line=$next_line&pos=$next_pos"; if ($first && $last) { print(qq{No other pages.
\n}); } else { print(qq{[prev page] }) if !$first; print(qq{[next page] }) if !$last; print(qq{
\n}); }