[Solved] How to align table headers to rows in Perl


#!/usr/bin/env perl

use strict;
use warnings;

use Text::Table::Tiny;

my @pName = (
    {
        "Type" => "xxxxxComponent",
        "Name" => "xyz_abc_1234LDO_c7rp1avrusevrmdtop",
        "Rev_Id" => "PROD_2_5",
        "ZZZ_ID" => '99ccccc1',
        "IP_Group" => "ABC RIP xxxxx",
        "Date_Released" => "2015-05-03 6:59:09",
        "AA_Category" => "Hard",
        "Project_IDs" => " ",
    },
    {
        "Type" => "xxxxxComponent",
        "Name" => "xyz_abc_1234LDO_c7rp1avrusevrmdtop",
        "Rev_Id" => "PROD_2_5",
        "ZZZ_ID" => '99ccccc1',
        "IP_Group" => "ABC RIP xxxxx",
        "Date_Released" => "2015-05-03 6:59:09",
        "AA_Category" => "Hard",
        "Project_IDs" => " ",
    },
);

my @header = qw(
    Type
    Name
    Rev_Id
    IRR_ID
    IP_Group
    Date_Released
    IP_Category
    Project_IDs
);

print Text::Table::Tiny::table(
    rows => [
        \@header,
        map [ @{$_}{@header} ], @pName
    ],
    header_row => 1,
);

Output:

+----------------+------------------------------------+----------+--------+---------------+--------------------+-------------+-------------+
| Type           | Name                               | Rev_Id   | IRR_ID | IP_Group      | Date_Released      | IP_Category | Project_IDs |
+----------------+------------------------------------+----------+--------+---------------+--------------------+-------------+-------------+
| xxxxxComponent | xyz_abc_1234LDO_c7rp1avrusevrmdtop | PROD_2_5 |        | ABC RIP xxxxx | 2015-05-03 6:59:09 |             |             |
| xxxxxComponent | xyz_abc_1234LDO_c7rp1avrusevrmdtop | PROD_2_5 |        | ABC RIP xxxxx | 2015-05-03 6:59:09 |             |             |
+----------------+------------------------------------+----------+--------+---------------+--------------------+-------------+-------------+%

3

solved How to align table headers to rows in Perl