Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Hosts List n' Country name

Posted on 2004-10-23
1
Medium Priority
?
160 Views
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
etc...
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:
Text1.txt:
blablabla.com.ar Argentina
blablabla.co.uk United Kingdom

Tnx!
0
Comment
Question by:cels9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 12391134
#!/usr/bin/perl
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;
}
     
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
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…
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

618 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