What‽ No love for jeffa's new Spreadsheet::HTML‽
#!/usr/bin/perl -w use strict; use Spreadsheet::HTML; my %hash = ( kumquat => 'orange', pomegranate => 'red', cherimoya => 'green', ling +onberry => 'purple' ); my $data = [ [sort keys %hash], [sort { $a cmp $b } values %hash] ]; my $generator = Spreadsheet::HTML->new( data => $data, matrix => 1, # no <th> indent => ' ' ); print $generator->portrait; __END__
Output:
<table> <tr> <td>cherimoya</td> <td>kumquat</td> <td>lingonberry</td> <td>pomegranate</td> </tr> <tr> <td>green</td> <td>orange</td> <td>purple</td> <td>red</td> </tr> </table>
Now if there was just a way to make a callback sub that would color the table cells with the fruit colors ...
#!/usr/bin/perl -w use strict; use Spreadsheet::HTML; my %hash = ( kumquat => 'orange', pomegranate => 'red', cherimoya => 'green', lin +gonberry => 'purple' ); my ($fruits, $colors) = ( [sort keys %hash], [sort { $a cmp $b } value +s %hash] ); my $data = [ $fruits, $colors ]; my $generator = Spreadsheet::HTML->new( data => $data, indent => ' ', th => { style => { background => $colors } }, td => [ sub { my $c = shift; $c =~ s!(.*)!<font color="$1">$1</f +ont>!; return $c } ], ); print $generator->portrait; __END__
Output:
<table> <tr> <th style="background: green">cherimoya</th> <th style="background: orange">kumquat</th> <th style="background: purple">lingonberry</th> <th style="background: red">pomegranate</th> </tr> <tr> <td><font color="green">green</font></td> <td><font color="orange">orange</font></td> <td><font color="purple">purple</font></td> <td><font color="red">red</font></td> </tr> </table>
Yep, I know this is deprecated HTML; just playing :-)
In reply to Re: Table in Perl CGI
by 1nickt
in thread Table in Perl CGI
by alokranjan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |