开发者

How to download .gz file using Perl

I want to download files with .gz extension using Perl. I have wrote the following code:

#!/usr/bin/perl

use strict;
use warnings;

use LWP::Simple;

my $url = 'http://www.ebi.ac.uk/thornton-srv/databases/pdbsum/2kri/igrow.out.gz';开发者_如何学Python
my $file = 'prot-prot.txt';

getstore($url, $file);

But I have realized that this code only works with text files and not compressed files. Any idea how I should change this code in order to download .gz files?

Thanks;


#!/usr/bin/perl

use strict;
use warnings;

use LWP::Simple;

my $url = 'http://www.ebi.ac.uk/thornton-srv/databases/pdbsum/2kri/igrow.out.gz';
my $file = 'igrow.out.gz';

getstore($url, $file);

If you want the perl script to unzip the file, you can either uses system() to run gunzip or search CPAN for a suitable perl module.

if you don't like typing 'igrow.out.gz twice (with the possibility of forgetting to change one of the filenames) replace $file = ... with something like

 (my $file = $url) =~ s!^.*/!!;


Use File::Fetch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜