problem Gunzip um arquivo em perl [closed]

1

Eu tenho abaixo do arquivo: 9001_20150918165942_00085.xml.gz

Eu quero gunzip "9001_20150918165942_00085.xml", como posso fazê-lo em perl.

Atenciosamente, Bhushan

    
por Bhushan Patil 18.09.2015 / 13:06

1 resposta

1

O caminho mais fácil via system

#!/usr/bin/env perl
system("gunzip 9001_20150918165942_00085.xml.gz")

ou

#!/usr/bin/env perl
system("gunzip","9001_20150918165942_00085.xml.gz");

O caminho nativo do 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
#!/usr/bin/env perl
system("gunzip 9001_20150918165942_00085.xml.gz")
" ) 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"; }

Fonte

    
por A.B. 18.09.2015 / 13:09