#!/usr/bin/perl ## PerlTail ## Does a "tail" of a file using seek. use strict; my $bigfile = shift or die "Usage: $0 filename \n"; my $linesback = shift || 10; ## How many "lines" back to read my $charsperline = shift || 80; ## A rough guess open(BIG, $bigfile) or die "Could not open $bigfile: $!\n"; ## Make a reasonable guess as to how far back to go. my $gobackchars = $linesback*$charsperline+1; ## Figure out how big it is my $filesize = -s $bigfile; ## We do not want to go back *too* far: $gobackchars = $filesize if $gobackchars > $filesize; seek(BIG,-$gobackchars,2); ## We probably arrived in the middle of a line, ## so throw out everything to the start of a new line ; ## Now we print out the rest of the lines: print while(); close(BIG);