Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^2: Pointers needed to tweak a sort

by Lady_Aleena (Curate)
on Jul 02, 2012 at 21:55 UTC ( #979545=note: print w/replies, xml ) Need Help??

in reply to Re: Pointers needed to tweak a sort
in thread Pointers needed to tweak a sort

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979545]
[erix]: yeah, SQLite may well be the most-used SQL database on earth
[ambrus]: erix: further, SQLite may be the second most installed piece of software on earth after zlib.

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2017-09-25 14:12 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (280 votes). Check out past polls.