Created
December 16, 2013 11:31
-
-
Save ovntatar/7985680 to your computer and use it in GitHub Desktop.
LWP Callback
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
#!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