Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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?

In reply to Non-DB table sorting by Xaositect

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-29 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found