Skip to content

Instantly share code, notes, and snippets.

@warewolf
Created May 3, 2020 21:41
Show Gist options
  • Save warewolf/8676e939ac995486092ca55497e98b1c to your computer and use it in GitHub Desktop.
Save warewolf/8676e939ac995486092ca55497e98b1c to your computer and use it in GitHub Desktop.
sort human-wise by domain names
#!/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