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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.