| 1 | package My::Array; | ||
| 2 | |||
| 3 | use v5.32; | ||
| 4 | use Mojo::Base -strict; | ||
| 5 | use List::Util qw( max ); | ||
| 6 | |||
| 7 | =head2 max_lengths | ||
| 8 | |||
| 9 | Returns an array of the lengths of | ||
| 10 | the longest strings per array. | ||
| 11 | |||
| 12 | Nice for making evenly spaced out tables. | ||
| 13 | |||
| 14 | =cut | ||
| 15 | |||
| 16 | sub max_lengths { | ||
| 17 | my ( $s, $rows ) = @_; | ||
| 18 | my $last_row = $rows->$#*; | ||
| 19 | my $last_column = $rows->[0]->$#*; | ||
| 20 | |||
| 21 | my @max = map { | ||
| 22 | my $col = $_; | ||
| 23 | max map { length $rows->[$_][$col]; } 0 .. $last_row; | ||
| 24 | } 0 .. $last_column; | ||
| 25 | |||
| 26 | \@max; | ||
| 27 | } | ||
| 28 | |||
| 29 | 1; |