Perl 解压缩log.gz文件

Perl 解压缩log.gz文件,perl,gunzip,Perl,Gunzip,我想解压缩昨天的多个log.gz文件 守则: use strict; use warnings; use 5.010; use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; use Time::Local; #yesterday my ($sec, $min, $hour, $mday, $mon, $year) = (gmtime())[0..5]; my $yesterday_midday=timelocal($sec,$min,$ho

我想解压缩昨天的多个log.gz文件

守则:

use strict;
use warnings;
use 5.010;
use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ;
use Time::Local;

#yesterday
my ($sec, $min, $hour, $mday, $mon, $year) = (gmtime())[0..5];

my $yesterday_midday=timelocal($sec,$min,$hour,$mday,$mon,$year) - 24*60*60;

($sec, $min, $hour, $mday, $mon, $year) = localtime($yesterday_midday);


my $path = sprintf "..\\..\\history\\%d\\%02d\\%02d\\*.log.gz",$year+1900, $mon+1, $mday;
print("PATH: $path\n");

gunzip '<path>' => '<#1.log>' #unzip all .log.gz files
        or die "gunzip failed: $GunzipError\n";

您需要展开标量
$path
在您的例子中,您告诉gunzip将名为
path
的文件解压缩到通配符输出中。错误告诉您,字符串“path”不包含任何通配符,但您引用的是匹配的通配符(由于“path”字符串中没有通配符,因此不存在该通配符)

试试这个:

gunzip "<$path>" => '<#1.log>' #unzip all .log.gz files
        or die "gunzip failed: $GunzipError\n";
gunzip'=>''解压所有.log.gz文件
或“gunzip失败:$gunziperor\n”;

是的,我的错,编辑。单引号将不会插入变量,它将按字面意思接受字符串。
gunzip "<$path>" => '<#1.log>' #unzip all .log.gz files
        or die "gunzip failed: $GunzipError\n";