Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm a newbie to Perl. I have a site with various external URLs in a flat-file database. If I have the URL in a variable in my program, what would I have to do to check the URL to see if it's dead or not?
I read through other similar questions. I didn't get it. One, I'm not sure if I have LWP. Two, I just didn't get it.
The best I found was this:
However, I'm clueless as to why it's a for. Also, it looks like it's reading from a default variable and I don't know how to set that. Could anyone explain either what this code is doing (line by line) or give me a better snippet of code? I don't need something that checks many links, just one.use strict; use IO::Socket::INET; for (@ARGV){ s|http://||; m|([^/]+)(.*)|; my $s=IO::Socket::INET->new(PeerAddr=>$1,PeerPort=>80,Proto=>'tcp',Ty +pe=>SOCK_STREAM); print $s "GET ".($2||'/')." HTTP/1.0\nHost: $1 \n\n"; print "Link $_ is validated\n" if <$s>=~/200 OK/; close $s; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Can You Explain How to Check a Link for Deadness
by choocroot (Friar) on May 12, 2002 at 19:39 UTC | |
by belg4mit (Prior) on May 12, 2002 at 19:44 UTC | |
Re: Can You Explain How to Check a Link for Deadness
by DigitalKitty (Parson) on May 12, 2002 at 20:19 UTC | |
by giulienk (Curate) on May 12, 2002 at 20:41 UTC | |
Re: Can You Explain How to Check a Link for Deadness
by tachyon (Chancellor) on May 13, 2002 at 01:18 UTC | |
Re: Can You Explain How to Check a Link for Deadness
by alien_life_form (Pilgrim) on May 12, 2002 at 20:51 UTC | |
Re: Can You Explain How to Check a Link for Deadness
by CharlesClarkson (Curate) on May 13, 2002 at 03:40 UTC |
Back to
Seekers of Perl Wisdom