in reply to Re: Align columns in a table
in thread Align columns in a table

That is awesome, thank you!
The syntax is a bit hard for me to read. How to assign the table into a string and print it at the end? Tried:
# $_ = sprintf "%%-%ds", length for @wide; $result = "%%-%ds", length for @wide;
Thank you again!

Replies are listed 'Best First'.
Re^3: Align columns in a table
by tybalt89 (Monsignor) on Aug 29, 2021 at 15:35 UTC
    #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11136164 use warnings; my @data = map [ /\S+(?: \(\S+)?/g ], <DATA>; my @wide; for my $line ( @data ) { $wide[$_] |= '' . $line->[$_] for 0 .. $#$line; } $_ = sprintf "%%-%ds", length for @wide; my $format = join(' ', @wide) . "\n"; #printf $format, @$_ for @data; # previous code my $table = join '', map { sprintf $format, @$_ } @data; # new combine + code print $table;