У меня есть файл ниже: 9001_20150918165942_00085.xml.gz
Я хочу заархивировать его "9001_20150918165942_00085.xml", как я могу сделать это в perl.
С уважением, Bhushan
Простой способ через system
#!/usr/bin/env perl
system("gunzip 9001_20150918165942_00085.xml.gz")
или
#!/usr/bin/env perl
system("gunzip","9001_20150918165942_00085.xml.gz");
Собственный Perl путь
#!/usr/bin/env perl
use strict;
BEGIN { @ARGV= map { glob($_) } @ARGV }
use Compress::Zlib;
die "Usage: $0 {file.gz|outfile=infile} ...\n"
unless @ARGV ;
foreach my $infile (@ARGV) {
my $outfile= $infile;
if( $infile =~ /=/ ) {
( $outfile, $infile )= split /=/, $infile;
} elsif( $outfile !~ s/[._]gz$//i ) {
$infile .= ".gz";
}
my $gz= gzopen( $infile, "rb" )
or die "Cannot open $infile: $gzerrno\n";
open( OUT, "> $outfile\0" )
or die "Can't write $outfile: $!\n";
binmode(OUT);
my $buffer;
print OUT $buffer
while $gz->gzread($buffer) > 0;
die "Error reading from $infile: $gzerrno\n"
if $gzerrno != Z_STREAM_END;
$gz->gzclose();
close(OUT)
or warn "Error closing $outfile: $!\n";
}