Hosts List n' Country name

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

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

Question by:cels9
1 Comment
LVL 85

Accepted Solution

ozo earned 2000 total points
ID: 12391134
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;

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans
Suggested Courses

601 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