in reply to sorting domains by extention
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: sorting domains by extention
by demerphq (Chancellor) on Aug 29, 2002 at 11:58 UTC |