sub get_object { my($agent, $url, $referer, $save_path); # args: LWP::UserAgent, url to get, (optional) referer to grab that url with, (optional) path to save it to my($request, $response, $content); # http stuff $agent = shift(); $url = shift(); $referer = shift(); $save_path = shift(); $request = HTTP::Request->new('GET', $url); $request->referer($referer) if ($referer); # if referer param is specified set it as the referer header $save_path ? print("Getting picture $url...") : print("Getting info from $url\n"); $response = $agent->request($request); $content = $response->content(); return($content) unless ($save_path); # if we're not saving it, return the html # now save it if (length($content) >= 5120) # check for a dud picture { open(OUT, ">$save_path") or die("Couldn\'t open picturefile to save: $!"); binmode(OUT); # if we're saving it it must be a picture, therefore binary print(OUT $content); close(OUT); return(1); } else { print("Picture was a dud."); return(0); } }