Saturday, January 29, 2011

How to know if document exists on a URL in perl

use LWP::Simple;
$URL='http://www.expertsguide.info/';
if (head($URL))
{
 print '$URL exists' ;
}
else
{
 print 'URL does not contain anything';
}

head() function returns much more information eg,  Content-type, document length, last modified time, expiry date and server name. Capture that using,
view sourceprint?

my @headers = head $URL;
print join "\n", @headers;

No comments: