To do the advertised function, the sub should extract the host from an URL, determine if the host is a domain, and strip down the domain to the company level.
The first part can be done using
defined( my $host = URI->new($url)->host() )
or die("Unable to determine the host of URL $url\n");
Instead, the presented sub attempts to do the first two parts at the same time and does a bad job.
- It finds a domain in some URLs that don't have a host.
- It finds a domain in some URLs that don't have a domain for host.
- It finds no domain in some URLs that do have a domain for host.
As for the third step, the sub just guesses as the OP admitted himself.
The posted sub also handles errors oddly, but that's trivial to fix.
This only works for single dot TLDs (.com, .net, .info, .ca, etc) and not intl TLDs like .co.uk etc with multiple dots.
Canada has .ca, .province.ca and .city.province.ca as suffixes, not just .ca. For example,
- tkf.toronto.on.ca - Toronto Kite Fliers
- senecac.on.ca - Seneca College
- ttc.ca - Toronto Transit Commission
company.ca used to only be available to federally incorporated institutions.
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, details, 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, summary, 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.