kcc kcc - 11 months ago 98
Perl Question

Gunzip .gz file in perl

I am working on Perl. and I need to download a .gz file from website, then gunzip or decompress it in Perl. My code:

use LWP::Simple;
use XML::Simple qw(:strict);
use Data::Dumper;
use DBI;
use Getopt::Long;
use IO::Uncompress::Gunzip qw($GunzipError);
use IO::File;

my $url = 'http://nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-Modified.xml.gz';

my $file = 'nvdcve-2.0-Modified.xml.gz';

getstore($url, $file);

my $xmlFile = 'nvdcve-2.0-Modified.xml';

gunzip $file => $xmlFile
or die "gunzip failed: $GunzipError\n";

I use the Uncompress to release the file. The file downloaded and stored in $file successful, but the gunzip code is not working. Appreciate for any help, thanks.

Answer Source

You must import the gunzip function into your namespace:

use IO::Uncompress::Gunzip qw(gunzip $GunzipError);