我有一个要使用Perl压缩的文件列表。目前我有这个:
gzip @tocompress -> $outputfile
or die "Failed to compress: $GzipErrorn"
但我想迭代这些文件,并一次将它们添加到压缩文件中。我怎样才能做到这一点?
您似乎在使用IO::Compress::Gzip。使用gzip
:的Append
选项
#!/usr/bin/perl
use warnings;
use strict;
use IO::Compress::Gzip qw{ gzip $GzipError };
my $outputfile = 'out.gz';
my @tocompress = glob '*.txt';
for my $file (@tocompress) {
next unless -f $file;
print STDERR "Adding $filen";
gzip($file, $outputfile, Append => 1) or die $GzipError;
}