sub set_column_widths { my $h = shift; # reference to hash table of speeds, keyed by datetime, then by database my $databases = shift; # reference to hash of database names, where we will set the width values my $names = shift; # ref to array of database names # (so we don't need to call keys on $databases repeatedly) for my $key (keys %$h){ for my $db (@$names){ my $l = length $h->{$key}{$db}; # get length of this item in the hash table # set column width to the widest length $databases->{$db} = $databases->{$db} > $l ? $databases->{$db} : $l; } } for my $db (@$names){ # check the width of the database names themselves too my $l = length $db; $databases->{$db} = $databases->{$db} > $l ? $databases->{$db} : $l; } }