Skip to content

Instantly share code, notes, and snippets.

@ovntatar
Created December 16, 2013 11:31
Show Gist options
  • Save ovntatar/7985680 to your computer and use it in GitHub Desktop.
Save ovntatar/7985680 to your computer and use it in GitHub Desktop.
LWP Callback
#!perl
use warnings;
use strict;
$|++;
use DDP;
use LWP;
die "Please enter URL as parameter.\n" unless @ARGV;
my $final_data = undef;
foreach my $url (@ARGV) {
print "Processing URL ", substr($url, 0, 40), "... ";
my $ua = LWP::UserAgent->new( );
my $response = $ua->get($url, ':content_cb' => \&callback, );
p $response;
print "\n";
}
sub callback {
my ($data, $response, $protocol) = @_;
$final_data .= $data;
print ".";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment