latin: pairwise loop through rows
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 2 Apr 2017 13:18:22 +0000 (15:18 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 24 Apr 2017 18:25:54 +0000 (20:25 +0200)
Treat as ordered hash instead of special-casing array references.

latin.plp

index 529b334574d421c496842bef61a00da396238c60..1fda12c5fb40846fa8cc49b62f11fb0c1cf93dd9 100644 (file)
--- a/latin.plp
+++ b/latin.plp
@@ -46,14 +46,19 @@ and <a href="/unicode">common chars</a>.</p>
 <div>
 
 <:
 <div>
 
 <:
+use List::Util qw( pairs );
+
 my @table = do 'writing-latn.inc.pl';
 if ($! or $@) {
        Alert("Table data not found", $@ || $!);
 }
 else {
        say '<table class="glyphs">';
 my @table = do 'writing-latn.inc.pl';
 if ($! or $@) {
        Alert("Table data not found", $@ || $!);
 }
 else {
        say '<table class="glyphs">';
-       print ref $_ ne 'ARRAY' ? "<tr><th>$_\n" : map {/^<td/ ? $_ : "\t<td>$_\n"} @$_
-               for @table;
+       for my $row (pairs @table) {
+               my ($title, $cells) = @{$row};
+               say '<tr><th>', $title;
+               print /^<td/ ? $_ : "\t<td>$_\n" for @{$cells};
+       }
        say "</table>\n";
 }
 
        say "</table>\n";
 }