Created
June 2, 2014 13:47
-
-
Save creaktive/6997782a95723524ca29 to your computer and use it in GitHub Desktop.
Net::Curl download progress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Net::Curl::Easy qw(:constants); | |
my $easy = Net::Curl::Easy->new; | |
$easy->setopt(CURLOPT_URL, 'http://www.cpan.org/modules/02packages.details.txt.gz'); | |
$easy->setopt(CURLOPT_WRITEDATA, \my $data); | |
$easy->setopt(CURLOPT_NOPROGRESS, 0); | |
$easy->setopt(CURLOPT_PROGRESSFUNCTION, sub { | |
my (undef, $dltotal, $dlnow) = @_; | |
printf "%0.2f%%\n", $dltotal ? 100 * $dlnow / $dltotal : 0; | |
return 0; | |
}); | |
$easy->perform; | |
printf "downloaded %d bytes\n", length $data; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment