Spanning and Sorting Your Data
By Randal L. Schwartz
I participate quite frequently in the Web-based community of Perl users known as the Monastery, located at perlmonks.org (www.perlmonks.org). Recently, a fellow "monk," as we call each other, wanted to know how to take a data table and generate pretty HTML from it. Simple tables aren't very difficult, but in this case many of the items in the table's vertical columns were identical. This monk wanted to span the identical data, to make the table easier to read.
The other monks proposed various solutions. One nice method used the HTML::Table module from the CPAN, which I had seen but not played with before. But, that solution spanned only the first columnthough in the authors' defense, that's all that was being asked. However, I saw this as an opportunity to take the idea one step further.
I wanted to generate a spanned HTML table from a dataset where any column could span, not just the first. To try this out, I'd need some sort of data: something with many similar vertical data rows.
"Aha!" I said, "How about the output of Unix's ps utility?" After a dozen more minutes, I was using a CGI script to grab ps output and dump it into wonderful spanned columns. When I hit reload, the values would change. In fact, I was rather amazed to see how much it cleaned up the output to have those spanned items there. Take a look at
Figure 1 to see what I mean.<>