Perl Readbackwards和gzipped文件

pyt*_*hor 2 perl gzip

我想从一个gzip压缩文件中逐行向后阅读.我知道ReadBackwards模块,但是如何才能使它在gzip压缩文件上运行?我应该使用不同的模块吗?

Cha*_*ens 7

你为什么要倒退呢?尝试向后读取压缩文件没有性能提升.您必须首先对其进行解压缩(以了解字节n意味着您必须先解压缩字节0 .. n).

你可能不会在速度方面变得更好:

#!/usr/bin/perl

use strict;
use warnings;

die "usage: $0 filename" unless defined(my $file = shift);

open my $fh, "<:gzip", $file
    or die "could not open $file: $!";

my @lines;
while (<$fh>) {
    push @lines, $_;
    shift @lines if @lines > 10;
}

print @lines;
Run Code Online (Sandbox Code Playgroud)