sub my_sort { my ($c,$d,$type) = @_; if ($c =~ /^index/) { return -1; } elsif ($d =~ /^index/) { return 1; } else { if ($c =~ /^ssi/) { return -1; } elsif ($d =~ /^ssi/) { return 1; } else { if ($type =~ /article/) { #written mostly by kent/n in #perl on freenode. for ($c, $d) { s/<.+?>//g; s/\s*\b(A|a|An|an|The|the)(_|\s)//xi; decode_entities($_); } $c = ucfirst($c) if $c =~ /^\l./; $d = ucfirst($d) if $d =~ /^\l./; $c =~ s/\B([A-Z])/\L$1/g; $d =~ s/\B([A-Z])/\L$1/g; if ($c =~ /^\d+$/ and $d =~ /^\d+$/) { return $c <=> $d; } else { return $c cmp $d; } } elsif ($type =~ /name/) { for ($c,$d) { s/\|.+$//; $_ = join(' ', (reverse split(/(?:_|\s)(?=[^_\s]+$)/, $_,2))) if $_ !~ /^_/; s/^_//; s/^(A|a|An|an|The|the)(_|\s)//; $_ = lc; } return $c cmp $d; } else { die(qq($type is not valid in the sort.)); } } } }