I need to initialize a hash of hashes. The way I do it is below, is there a more elegant way to do it?
$biggest_word_size = 0;
foreach $sig (@signals)
{
$sigs->{$sig} = "None";
$biggest_word_size =
( $biggest_word_size > length($sig) ) ? $biggest_word_size : length($sig) ;
}
To be honest, for what you want, this is pretty much as elegant as you want. You can do it in a slightly more idiomatic way, but why? It’s perfectly readable and concise enough
If the size of your array is not too large, and you don’t care about squeezing every last ounce of performane, you can do those 2 tasks separately in a slightly more idiomatic way (at the cost of scanning the array twice):