Skip to content

Instantly share code, notes, and snippets.

@creaktive
Created June 2, 2014 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creaktive/6997782a95723524ca29 to your computer and use it in GitHub Desktop.
Save creaktive/6997782a95723524ca29 to your computer and use it in GitHub Desktop.
Net::Curl download progress
#!/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