2016-09-28 92 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