Created
May 3, 2020 21:41
-
-
Save warewolf/8676e939ac995486092ca55497e98b1c to your computer and use it in GitHub Desktop.
sort human-wise by domain names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
$,="\n"; | |
print sort byd map{chomp;$_}<>; | |
print "\n"; | |
#sub byd($$){my ($a,$b)=map{lc join(".",reverse split m/\./,$_)}@_[0,1];$a cmp $b;} | |
sub byd($$) { | |
my ($a,$b) = @_[0,1]; | |
my ($da) = ($a =~ m/,?([^,]+)$/); my ($db) = ($b =~ m/,?([^,]+)$/); | |
#my ($da) = ($a =~ m/https?:\/\/([^\/]+)/); my ($db) = ($b =~ m/https?:\/\/([^\/]+)/); | |
my ($ra,$rb) = map { lc join(".",reverse split m/\./,$_) } ($da,$db); | |
#print STDERR "ra = $ra, rb = $rb\n"; | |
$ra cmp $rb; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment