[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Validating a URL with MacPerl



pudge@pobox.com (Chris Nandor) writes:
}At 7.34 97/4/2, Charles Cave wrote:
[snip]
}>
}>$badurl = "http//www.microsoft.moc"
}
}It depends on what you mean by "valid."  I am assuming that you mean that
}the address actually exists, in which case the only way to do it is to
}actually open a socket and see if you can connect.  Of course, a server
}could be down, and then it might be a valid URL but you wouldn't be able to
}connect anyway.
}
}But if you wanna do that, use LWP.
}
}  use LWP::Simple;
}
}  if (head($url)) {
}     # ok document exists
}  }
}
}Of course you might just mean, "does the URL conform to the set standards
}for URLs?"  If that is the case, then you would need to look up the RFC for
}it (the number I don't know) and check out the specs.  Also, as per your
}example, you would want to add a checker for the top-level-domains (TLDs,
}like .com and .edu), which would need to be flexible, as more TLDs are
}proposed and might exist within the year.
}
}I am not sure if LWP or any module can already check for proper URL syntax,
}or if someone has written a regex to check it.

A quick check doesn't turn up anything obvious in URI::URL, but, as with
the head check, you can always do "if it fails, it's bad" with
URI::URL->new.  If the URL object is successfully created, then apply
whatever other checks you desire.  The trickier part is identifying those
strings, like the one above, that are supposed to be URL's but aren't
because of the missing :.

I think I've seen Tom Christiansen post a regexp that "usually works" in
comp.lang.perl.misc.  Those interested can probably find it by hunting
around http://www.perl.com; it may be in one of the Perl FAQ's.

}
}#================================================================
}Chris Nandor                                      pudge@pobox.com
}PGP Key 1024/B76E72AD                           http://pudge.net/
}Keyfingerprint = 08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6


---
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693, Greenbelt, MD 20771
schinder@pjstoaster.pg.md.us