#! /usr/bin/perl -w use strict; use Data::Dump qw(pp); use WWW::Mechanize; my $url = 'http://perlmonks.org/images/vroom_sm.gif'; my $mech = WWW::Mechanize->new(); my $http_resp_obj = $mech->get( $url, ':content_file' => 'vroom_sm.gif' ); if ( $mech->success ) { # What if file buffer(s) haven't been flushed yet? print "File size is ", -s 'vroom_sm.gif', "\n"; # I could not figure out how to get the value of the 'content-length' key # despite examining the output from: # pp($http_resp_obj); print "Content length is $http_resp_obj->header('content-length')\n"; } else { warn "Failed to download '$url' (" . $mech->status() . ")\n"; }