Skip to content

Instantly share code, notes, and snippets.

@yevrah
Created April 28, 2015 05:19
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 yevrah/0db0f4aef865154e44eb to your computer and use it in GitHub Desktop.
Save yevrah/0db0f4aef865154e44eb to your computer and use it in GitHub Desktop.
Perl: Download files using libcurl
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Curl::Easy;
use File::Temp qw/tempfile/;
my ($out, $filename) = tempfile();
my $curl = WWW::Curl::Easy->new();
$curl->setopt(CURLOPT_URL, "https://github.com/libwww-perl/libwww-perl/archive/6.13.zip");
$curl->setopt(CURLOPT_WRITEDATA,$out);
$curl->setopt(CURLOPT_VERBOSE,1);
$curl->setopt(CURLOPT_FOLLOWLOCATION,1);
my $retcode = $curl->perform();
if ($retcode != 0) {
print STDERR "Fetch Failed: ", $curl->strerror($retcode), " ( +$retcode)\n";
print STDERR "errbuf: ", $curl->errbuf;
exit(1);
} else {
print STDERR "Fetched file to: ", $filename, "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment