My contribution, cos it had to be done:^). Probably not the most efficient solution, but simple.
#! perl -w my @domains = qw(foo.com weirdext.za bar.uk.com blah.co.uk perl.pl zzz +z.co.uk); my @sorted = map{ join '.', reverse split( /\|/,$_ ) } sort map {join '|', reverse split( /\./,$_,2) } @domains; { local $"="\n"; print "@sorted"; } __END__ # Output C:\test>193114 blah.co.uk zzzz.co.uk foo.com perl.pl bar.uk.com weirdext.za C:\test>
I know that the result is slightly different from your 'desired output' example, but I thought about this for a long time, and whilst I'm probably wrong as noone else has mentioned it, I can see no criteria by which bar.uk.com could be sort in the position you have it?
If its grouped with foo.com, because they both have a .com extension, then bar.uk sorts before foo.
If its after foo.com because .uk.com is lexically higher that .com, then .uk.com is also higher than .pl, which is what I think that you are asking for.
In reply to Re: sorting domains by extention
by BrowserUk
in thread sorting domains by extention
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |