user
Create an HTML table.

* The table body should have at least three rows of three columns.
* Each of these three columns should be labelled "X", "Y", and "Z".
* An extra column should be added at either the extreme left or the extreme right of the table that has no heading, but is filled with sequential row numbers.
* The rows of the "X", "Y", and "Z" columns should be filled with random or sequential integers having 4 digits or less.
* The numbers should be aligned in the same fashion for all columns.
assistant
(formerly Perl 6)

The below example is kind of boring, and laughably simple. For more interesting/complicated examples see:

Show\_Ascii\_table#Raku - *(simple)*  
Mayan\_numerals#Raku - *(heavy styling)*  
Rosetta\_Code/Count\_examples/Full\_list - *(multi-column sortable)*  
Rosetta\_Code/List\_authors\_of\_task\_descriptions/Full\_list - *(complex nested tables)*

*Note: the above examples are outputting wikitable formatting, not HTML directly. It's pretty much a one-for-one shorthand notation though and the principles and process are the same.*

This is certainly not the only or best way to generate HTML tables using Raku; just an example of one possible method.

```
my @header =  <&nbsp; X Y Z>;
my $rows = 5;

sub tag ($tag, $string, $param?) { return "<$tag" ~ ($param ?? " $param" !! '') ~ ">$string" ~ "</$tag>" };

my $table = tag('tr', ( tag('th', $_) for @header));

for 1 .. $rows -> $row { 
    $table ~=  tag('tr', ( tag('td', $row, 'align="right"')
    ~ (tag('td', (^10000).pick, 'align="right"') for 1..^@header)));  
}

say tag('table', $table, 'cellspacing=4 style="text-align:right; border: 1px solid;"');

```

Output:

|  | X | Y | Z |
| --- | --- | --- | --- |
| 1 | 2179 | 4778 | 2717 |
| 2 | 2160 | 1592 | 4348 |
| 3 | 4511 | 540 | 7187 |
| 4 | 3484 | 5882 | 1273 |
| 5 | 1310 | 4017 | 410 |