Deane,

Consider altering your routine to something like this:

my @Fields = split(/\./,$url);
my $Domain;
$Domain = $Fields[-2] . '.' . $Fields[-1] if (@Fields == 3);
$Domain = $Fields[-3] . '.' . $Fields[-2] . '.' . $Fields[-1] if
(@Fields == 4);

Note that you could get tricky with a for loop to assign $Domain.

Dirk Bremer - Senior Systems Engineer - ESS/AMS - NISC Lake St. Louis MO
- USA Central Time Zone
636-755-2652 fax 636-755-2503

[EMAIL PROTECTED]
www.nisc.coop 

________________________________

        From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
        Sent: Wednesday, April 26, 2006 09:08
        To: [email protected]
        Subject: Got this far with regex, now I'm stumped
        
        

        Hi, all. 
        
        I have a sub that uses a set of URL-parsing regexes that almost
works: 
        
        if ($url =~ m{^(.*)\.([^\.]+\...\...)$}) { 
           $domain = $2; 
           $child = $1; 
        } 
        else { 
           if ($url =~ /^[^\.]+?\.\w{2,4}$/) { 
              $domain = $url;                                   #
"www.xx.yy" should have ended up here. . . 
           } 
           else { 
              $url =~ m{^(.*)\.(.+\.\w{2,4}).*$};      # . . . but it
ended up here 
              $domain = $2; 
              $child = $1; 
           } 
        } 
              
        It catches almost all the URL formats it needs to, like
"www.defgh.xx.yy", but it misses one possible format, "www.xx.yy". For
this URL the sub that uses the regex returns "xx.yy" as the domain and
"www" as the child, which means that there's still something not quite
right with the regex in the second if statement. The sub should've
returned "www.xx.yy" as the domain, with no child. See the comments in
the code sample for where that URL landed, vs. where it should've
landed. 
        
        I've ordered "Mastering Regular Expressions" but it hasn't
arrived yet, so any help would be appreciated. 
        
        Thanks, 
        
        Deane 
        


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

Reply via email to