Don't ask to ask, just ask | |
PerlMonks |
Re: sorting mm/dd/yyby InfiniteSilence (Curate) |
on Dec 15, 2000 at 21:40 UTC ( [id://46867]=note: print w/replies, xml ) | Need Help?? |
I mostly wrote the following as a tutorial to myself as to how Perl's sorting function works:
Quick explanation The first and second sorts use Perl's standard sorting syntax. Nothing special here. Perl also allows you to call a special sorting routine sort {date_sort($a, $b)} @b where the stuff between the curly braces is your call to the special function. The function basically checks the date and returns either one of two options...either $a is greater than $b or the reverse. This is a very involved way to sort some bloody dates but, if you think about it, you could reuse the code if you needed a very, very specialized kind of date comparison function...e.g. perhaps something that seeks a particular range of dates and places them at the top of the sort order or something.
Oops...I tried a different set for the test data for this function and I am getting incorrect results. Don't use this for dates < 1950. Celebrate Intellectual Diversity
In Section
Seekers of Perl Wisdom
|
|