Make a list of colours with HTML::Make

This example Perl script demonstrates making a list containing some Japanese colours I found on a set of coloured Magic Ink pens I bought. This is what the coloured pens look like:

DSC_6639

This example uses HTML::Make. The list of colours comes from Traditional colors of Japan.

#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use utf8;
use HTML::Make;
my @colours = (
    daidai => 0xEE7800,
    murasaki => 0x884898,
    kimidori => 0xB9C42F,
    kogecha => 0x6A4D32,
    uguisuiro => 0x838B0D,
);
my $ul = HTML::Make->new ('ul');
while (@colours) {
    my $colour = shift @colours;
    my $rgb = shift @colours;
    # Here we make a new element and then push it into $ul, rather
    # than using the return value of $ul->push ().
    my $li = HTML::Make->new (
        'li', text => $colour,
        attr => {
            style => sprintf ("background: #%06X", $rgb),
        });
    $ul->push ($li);
}
print $ul->text ();

(download)

As HTML, the output looks like this:

The HTML output looks like this:

<ul>
<li style="background: #EE7800">daidai</li>
<li style="background: #884898">murasaki</li>
<li style="background: #B9C42F">kimidori</li>
<li style="background: #6A4D32">kogecha</li>
<li style="background: #838B0D">uguisuiro</li>
</ul>


Copyright © Ben Bullock 2009-2017. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com). / Privacy / Disclaimer