[EMAIL PROTECTED] wrote:
>
> I'm doing some splitting of URLs, and things are getting more and more
> complicated, what with suddenly needing to allow two, three, or even
> four character TLDs (.us, .gov, .info). I originally thought I'd only
> need to pass a few common threes--such as .com.
>
> Is there a standard Perl library routine (can't use CPAN) that divides
> up URLs?
Try lloking at URI.pm or URI::Split.pm
> This seems like a common enough task that this particular wheel
> might already exist. All I need to do is split something like
> "foo.bar.com" into "foo" and "bar.com". It's for the second bit, the
> domain, where this issue is suddenly sprouting horns and a pointy tail.
> Oh, it also needs to ignore any trailing thingies like
> "foo.bar.com/ignore/this/".
>
> Current code is:
>
> if ($in =~ /^[^\.]+?\.(com|gov|net|org)$/) {
> $domain = $in;
> } else {
> $in =~ m{^(.*)\.(.+\.(com|gov|net|org)).*$};
> $domain = $2;
> $child = $1;
> }
>
> where $in is the URL, less any prefix. The prefixes, "http://" or
> "https://", are already handled by preceding lines, as are any "trailing
> thingies."
>
> I've thought of using [a-z]{2,4} to replace the list in the regexps, but
> that places a big ol' "CAVEAT EMPTOR" in front of the users--one I hope
> might be avoidable. Plus, I'm afraid of other things popping up, like,
> oh, "dnr.state.wi.us", which is a real URL for Wisconsin DNR, or
> something like "foo.us.gov". Both of which would FAIL the current code,
> as well as the [a-z]{2,4} kludge.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs