2016-09-28 90 views
1

我正在使用Perl。我需要从网站上下载.gz文件,然后用gunzip或者用Perl解压缩。我的代码:perl中的gunzip .gz文件

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"; 

我使用解压缩来释放文件。该文件下载并存储在$文件成功,但gunzip代码不起作用。感谢您的帮助,谢谢。

+0

缺少'使用LWP :: Simple' – ssr1012

+0

@ ssr1012您好我用,我只是没有复制行,谢谢。 – kcc

+0

与_gunzip“死”是否失败:_? '$ GunzipError'中有什么? – simbabque

回答

2

必须导入gunzip功能到您的命名空间:

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

非常感谢,它的工作。 – kcc