No, there is no "standard perl routine" for splitting host names.
  You need to take a step back from your problem and consider it from a
more general view.  You seem to want to break up a host name into a
"child" and a "domain".  
  What is your definition of "domain"?  It sounds like you want "domain"
to be "the last N dot-separated portions of the hostname, where N >= 2";
and then you want "child" to be "the portion of the hostname in front of
the domain".  Or maybe you want to define "child" to be "the first
portion of the hostname, unless there are only 2 portions"; and then
"domain" is "the portion of the hostname after the child".  We can not
make these definitions for you, because that is not how the DNS naming
standard is defined.
  Once you have defined what you mean by "child" and "domain", you can
easily construct regex to grab what you want.
  I won't bother to ask you to explain the "can't use CPAN" rule... But
how is asking for help on a mailing list different from using CPAN?
  P.S. Please send ONLY PLAIN TEXT email to mailing lists.
 - - Martin


________________________________

        From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
        Sent: Wednesday, April 19, 2006 11:05
        To: [email protected]
        Subject: URL parsing
        
        

        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? 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. 
        
        HELP! 
        
        TIA, 
        
        Deane 
        


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to