PERL: How to create a table from a table?

advertisements

I have an array like this

@array = (
           1,
           some 9-digit number-1,
           some 9-digit number-2,
           2,
           some 9-digit number-3,
           some 9-digit number-4
           .....and so on
);

Now I want to print this in a table as

1    some 9-digit number-1  some 9-digit number-2
2    some 9-digit number-3  some 9-digit number-4
3    some 9-digit number-5  some 9-digit number-6

I also want to print the table to a text file. What logic would be the best ?

Thanks


I figured it out. I used Text::Table Thanks – John F

use Text::Table;
my $tb = Text::Table->new( "Heading 1", "Heading 2" , "Heading 3");

for (my $i = 0; $i <= $#array; $i += 3) {
    $tb->load([@array[$i, $i+1, $i+2]]);
}

print $tb;