[英]How to gzip several files in Perl one by one
I have a list of files that I want to compress using Perl. 我有要使用Perl压缩的文件列表。 Currently I have this:
目前我有这个:
gzip \@tocompress -> $outputfile
or die "Failed to compress: $GzipError\n"
But I want to iterate over the files and add them one at the time to the compress file. 但是我想遍历文件,然后一次将它们添加到压缩文件中。 How can I achieve that?
我该如何实现?
It seems you're using IO::Compress::Gzip . 看来您正在使用IO :: Compress :: Gzip 。 Use the
Append
option of 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 $file\n";
gzip($file, $outputfile, Append => 1) or die $GzipError;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.