- 论坛徽章:
- 7
|
#!/usr/bin/perl
use strict;
use warnings;
# For the SEEK_* constants
use Fcntl qw(:seek);
use File::ReadBackwards;
my $LINES = 10; # Change to 125_000 or whatever
my $File = shift; # file passed in as argument
my $rbw = File::ReadBackwards->new($File) or die $!;
# Count backwards $LINES or the beginning of the file is hit
my $line_count = 0;
until( $rbw->eof || $line_count == $LINES ) {
$rbw->readline;
$line_count++;
}
# Get the real filehandle out of the File::ReadBackwards
my $fh = $rbw->get_handle;
# Chop off everything from that point on.
truncate($File, $rbw->tell); |
|