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.));
}
}
}
}
my_sort strips off articles and alphabetizes numbers as numbers (2100 AFTER 22). The index and ssi sorting are there until I finally wipe out all .ssi files from my site, which may never happen since I'm low on imagination for coding those pages. It also alphabetizes names last name then first name. This was written a long time ago with help.
Have a cookie and a very nice day!
Lady Aleena
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|