开发者

How to download .gz file using Perl

开发者 https://www.devze.com 2023-03-24 06:33 出处:网络
I want to download files with .gz extension using Perl. I have wrote the following code: #!/usr/bin/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

精彩评论

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

关注公众号