When I wish to print a scalar, array, or hash as a table, I turn to one of these subroutines:

 
# perl0004.lib
# Written:  1999-06-07  James Alarie
#
# table_s
#   border, bgcolor, scalar_item
# table_a
#   border, bgcolor, array_item, columns
# table_h
#   border, bgcolor, hash_item

sub table_s{                                        # scalar
  print "\n<table border=$_[0]>\n";
  print "  <tr>\n";
  print "    <td>$_[2] bgcolor=$_[1]</td>\n";
  print "  </tr>\n";
  print "</table>\n";
}


sub table_a{                                        # array
  local($columns, $count, $ix1, $ix2);
  print "\n<table border=$_[0]>\n";
  $columns = pop(@_);
  shift(@_);
  shift(@_);
  $ix1 = 1;
  $count = $#_ + 1;                 # number of items
  $ix2 = 0;
  while ($ix2 < $count) {
    print "  <tr>\n";
    for ($ix1 = 1; $ix1 <= $columns; $ix1++) {
      print "    <td bgcolor=$_[1]>@_[$ix2 + $ix1 - 1]</td>\n";
    }
    print "  </tr>\n";
    $ix2 += $columns;
  }
  print "</table>\n";
}


sub table_h{                                        # hash
  local($key, $value, %hash);
  print "\n<table border=$_[0]>\n";
  shift(@_);
  shift(@_);
  %hash = @_;
  foreach $key (sort keys(%hash)) {
    $value = $hash{$key};
    print "  <tr>\n";
    print "    <td bgcolor=$_[1]>$key</td>\n";
    print "    <td bgcolor=$_[1]>$value</td>\n";
    print "  </tr>\n";
  }
  print "</table>\n";
}


#***** Accessed correctly:
1;