Hosts List n' Country name

Posted on 2004-10-23
Last Modified: 2010-03-05
I have a list of URL terminations n the respectives countrues... for exemple: United kingdom
.ch chile
.com International
and a list of valid urls...: Text1 text2 Text1 text2

the script will do this:
I execute the command: perl Text1(to find) URLS.txt
will create a file called Text1.txt(the text1 that is in the url line) and write into the and the and the name of the country. Ex:
Text1.txt: Argentina United Kingdom

Question by:cels9
    1 Comment
    LVL 84

    Accepted Solution

    use strict;
    my($text,$urls) = @ARGV;
    open URLS,"<$urls" or die "Can't read $urls $!";
    my %TLD;
    while( <URLS> ){
        next unless my($TLD,$country) = /(\.[^.]+?)\s+(.*)/;
         $TLD{$TLD} = $country;
    open TEXT,"<$text" or die "Can't read $text $!";
    while( <TEXT> ){
        next unless my($URL,$TLD,$file) = /(\S*(\.[^.]+?))\s+(\S+)/;
        open FILE,">>$file.txt" or die "Can't append to $file.txt $!";
        print FILE "$URL ".($TLD{$TLD}||"Unrecognized Top Level Domain")."\n";
        close FILE;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    857 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now