
rGeoffrey
User
/ Moderator
Nov 13, 2000, 11:42 AM
Post #3 of 3
(1387 views)
|
If you are going to be sorting numerically rather than asciibetically, then you need to do something a little stronger than just 'sort', like ... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> sort { $a <=> $b } keys %include </pre><HR></BLOCKQUOTE> I ran into a similar table problem recently. Below is a function based on my problem made to fit your data. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> &Print_Table (6, 'header message', sort { $a <=> $b } map { ($include{$_} eq 'yes') ? $_ : () } (keys %include)); sub Print_Table { my ($columns, $message, @names) = @_; $columns = (@names > $columns) ? $columns : scalar (@names); print "<table border='0' cellpadding='0' cellspacing='0' WIDTH='100%'>"; print (qq[\n<tr><th colspan="$columns">$message</th></tr>\n]) if ($message); while (@names) { print ("<tr>\n", (map { "<td align='center'><FONT SIZE='-1'>$_</font></td>\n" } splice (@names, 0, $columns)), "</tr>" ); } print "</table>\n"; } </pre><HR></BLOCKQUOTE> The function will take a number of columns and an optional header for the 'th' tag that will span the whole table on the first line. If you don't want it just send an empty string ('') in the second position. The nice thing about this function is that if you have an array that is shorter than the proposed width of the table, it will take care of that for you. Also I moved the checking for 'yes' outside of the printing of the table and placed it between the keys and the sort. [This message has been edited by rGeoffrey (edited 11-13-2000).]
|