The code above generates duplicates (i.e. the same
TLD will be generated more than once). Consider:
'a'.'a'.'a'.'a'.''.''
'a'.'a'.'a'.''.'a'.''
'a'.'a'.'a'.''.''.'a'
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);
}
}
| [reply] [Watch: Dir/Any] [d/l] |
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
('aaa'..'zzzzzz')
That's all :) | [reply] [Watch: Dir/Any] [d/l] |
| [reply] [Watch: Dir/Any] [d/l] |