Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Non-DB table sortingby Xaositect (Friar) |
on Aug 10, 2002 at 03:04 UTC ( [id://189128]=perlquestion: print w/replies, xml ) | Need Help?? |
Xaositect has asked for the wisdom of the Perl Monks concerning the following question:
I'm putting together a web page table, and using it (among other things) as a chance to learn some perl. I'd like to provide the user with sort-by-column functionality. The data set isn't big enough to warrant a real database behind the scenes, but it's also big enough to make client-side JavaScript sorting questionable. (Tendancy to "hang" while it sorts, at least if a page is reloading the user knows something is happening) The obvious language-independant server-side approach here is to load the entire dataset into a 2D array, sort, and iterate through the first dimension while printing table rows. This seemed like a straightforward task, perl provides a sort function that accepts a sub to compare (sort) with. Loading the data into a list of lists is easy enough, however, I'm a little confused regarding how the reference syntax would work in this sort sub. This seems like a common type of task, sorting by something other than the first index in a list of lists, does anyone have a solution they're particularly proud of?
Back to
Seekers of Perl Wisdom
|
|