How to know if document exists on a URL in perl

Pinging a server doesn’t not actually tell if the web server is up and available or not. To check if a server is available and responding or a document exists on a URL, use this,

use LWP::Simple;
if (head($URL))
   print '$URL exists' ;
   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,

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>