in reply to Can You Explain How to Check a Link for Deadness

I don't need something that checks many links, just one.

Hi.

One 'quick and dirty' solution is to use the LWP::Simple module and check the return value of the url that was entered.

#!/usr/bin/perl -w use strict; use LWP::Simple; my $url; my $site; print "URL to check: "; chomp($url = <STDIN>); $site = get($url); if($site) { print "$url is good.\n"; } else { print "$url appears to be broken.\n"; } Sample run with output: C:\perl>perl linkcheck.pl URL to check: http://www.perlmonks.org http://www.perlmonks.org is good. C:\perl>perl linkcheck.pl URL to check: http://www.google.com http://www.google.com is good. C:\perl>perl linkcheck.pl URL to check: http://www.blahblahblah.com http://www.blahblahblah.com appears to be broken. C:\perl>


Hope this helps,

-DigitalKitty

Replies are listed 'Best First'.
Re: Re: Can You Explain How to Check a Link for Deadness
by giulienk (Curate) on May 12, 2002 at 20:41 UTC
    Substituting the call to the get function in the LWP::Simple for a call to head you could save a good amount of time as the head function checks only for the presence of the page instead of downloading it all.


    $|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g