Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

TLD generator

by j.a.p.h. (Pilgrim)
on Jul 17, 2000 at 04:56 UTC ( #22805=sourcecode: print w/replies, xml ) Need Help??
Category: Web Stuff
Author/Contact Info Daniel Cormier
Description: Ever get a bit ticked off about the lack of TLDs/domains available? I wrote this little program to print out every possable 3-6 letter TLD. If ICANN would approve them all, I doubt it would be a problem anymore. But there's litte to no chance of that happening (at least any time soon).
#!/usr/bin/perl -w
# This was created to print out a list of all TLDs possable which are
# 3, 4, 5 and 6 characters long.
# This program will run for quite some time if you let it. I recommend
# hitting ^C after a short time. Espicially if you want to have it wri
+te to a file.
# I DO NOT recommend having it write to a file do the the huge dataset
+ it creates.
# If you do have it write to a file, the fault is in no way mine. The 
+author will not
# be held responsible for your actions.

# Letters and Numerals
@chars = qw(a b c d e f g h i j k l m n o p q r
        s t u v w x y z 0 1 2 3 4 5 6 7 8 9);

# Letters, Numerals and a null. If I don't have this, the program will
+ only return
# TLDs with 6 characters. This way, it return TLDs with 3-6 characters
@charsnull = (@chars,"");

foreach $char (@chars){
    $tld = $char;

    foreach $char (@chars){
        $tld2 = $tld . $char;     # to see why I did it this way, run 
+the program
                        # so everything is appended to $tld and watch 
+the output.
        foreach $char (@chars){
            $tld3 = $tld2 . $char;

            foreach $char (@charsnull){
                $tld4 = $tld3 . $char;

                foreach $char (@charsnull){
                    $tld5 = $tld4 . $char;

                    foreach $char (@charsnull){
                        $tld6 = $tld5 . $char;
                        print "$tld6\n";     # if you try the above co
+mment, be sure
                        #to change all the $tld(insert number here) va
+rs, to just, $tld.





Replies are listed 'Best First'.
RE: TLD generator
by lhoward (Vicar) on Jul 17, 2000 at 07:05 UTC
    The code above generates duplicates (i.e. the same TLD will be generated more than once). Consider:
    The following does not have the duplicates problem. It could be optimized a bit (and shortened too), but I leave that as an exercise to the reader...
    #!/usr/bin/perl -w use strict; my @chars=(('a'..'z'),(0..9)); tld('',$_) for (3..6); sub tld{ my ($txt,$cnt)=@_; if($cnt==0){ print "$txt\n"; }else{ tld($txt.$_,$cnt-1) for (@chars); } }
      Agreed. Recursion suggests itself in this case.
      And much better - is to get rid of digits and then just use strings increment. So it will be just
      That's all :)
        now your missing numbered TLD's though :)

        /****************************/, /*****************************/
RE: TLD generator
by setantae (Scribe) on Jul 17, 2000 at 11:58 UTC
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://22805]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2016-10-25 22:14 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (330 votes). Check out past polls.