sub my_sort_article { my ($c,$d,$type) = @_; $c = lc($c); $d = lc($d); my $t = my_sort_index($c, $d); return $t if $t; # Written with the help of kent/n in #perl on freenode. for ($c, $d) { s/<.+?>//g; # Strip out any html tags. s/\s*\b(A|a|An|an|The|the)(_|\s)//xi; # Strip off leading articles (in English). decode_entities($_); } if ( $c =~/^((\d|,|\.)+)(.*)$/ && $d =~ /^((\d|,|\.)+)(.*)$/) { # Get the leading number. (my $e = $c) =~ s/^((\d|,|\.)+)(.*)$/$1/; (my $f = $d) =~ s/^((\d|,|\.)+)(.*)$/$1/; # Take any commas out of the number. s/,//g for ($e,$f); # Get the remaining parts of the string. (my $g = $c) =~ s/^((\d|,|\.)+)(.*)$/$3/; (my $h = $d) =~ s/^((\d|,|\.)+)(.*)$/$3/; # First compare the numbers, then compare the remaining parts of the string. $e <=> $f || $g cmp $h } else { $c cmp $d; } } sub my_sort_name { # When I sort by name I prefer lastname firstname. # I have not yet written this to account for Sr., Jr., or Roman numerals after the last name. my ($c,$d,$type) = @_; $c = lc($c); $d = lc($d); # ?Did you really want this check for name sorting? my $t = my_sort_index($c, $d); return $t if $t; for ($c,$d) { s/\|.+$//; $_ = join(' ', (reverse split(/(?:_|\s)(?=[^_\s]+$)/, $_,2))) if $_ !~ /^_/; s/^_//; s/^(A|a|An|an|The|the)(_|\s)//; } return $c cmp $d; }