|Think about Loose Coupling|
Pivoting parts of a database table into an HTML tableby Anonymous Monk
|on Oct 22, 2012 at 08:00 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
O Monks, hallowed be your woodiness.
For a variety of reasons, I'm collecting words alongside their date of encounter into a database. Then I group them by their woodiness or tinniness. The database table has three columns and looks like this:
Now, to create a more compact view, I'd like to transform the one-word-per-row raw data into an HTML table grouped by date like this:
However, I'm having quite a bit of trouble with the loop logic. I can manage the grouping to date, but the special cases of days where only one type of words appear don't quite work and either the words go into the wrong column or the column is left without (empty) markup.
(I actually created a nice generic function that was supposed to solve this sort of task, but it ended up lacking in a few ways. Its interface borders on the silly (expects 4+ subrefs.))
Attached is sample data along with an iterator that emulates a database query handle.