Quite a few interesting replies came up for this thread!
I come up below piece of code to demon different solutions together. It displays a table that:
- The background color of each row is randomly generated, and keep the same for all cells in the row;
- The foreground color is generated by different solutions, identified by author's name.
To run it, just type:
perl -w blah.pl > result.html
And then use your browser to view result.html.
You will see that each siolution has its merit, and a different look and feel. I think, if you love fish, then take fish; if you love meat, then take meat, all delicious.
sub random_colors {
my ($r, $g, $b) = map { int rand 256 } 1 .. 3;
my $lum = ($r * 0.3) + ($g * 0.59) + ($b * 0.11);
my $bg = sprintf("#%02x%02x%02x", $r, $g, $b);
my $fg1 = sprintf("#%02x%02x%02x", ($r + 128) % 256, ($g + 128) %
+256, ($b + 128) % 256);
my $fg2 = $lum < 128 ? "white" : "black";
return ($bg, $fg1, $fg2);
}
for (1 .. 100) {
my ($bg, $fg1, $fg2) = random_colors();
print qq{
<table>
<tr>
<td bgcolor=$bg><font size=5 color=$fg1>pg</font></td>
<td bgcolor=$bg><font size=5 color=$fg2>blokhead</font></t
+d>
</tr>
</table>
};
}
Here is just a piece of it:
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.