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:
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;
}
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|