tomdbs98 has asked for the wisdom of the Perl Monks concerning the following question:
I have two references to hashes of arrays: $best and $kept_best. Each array in $best will have 10 elements and each array in $kept_best will have at most 10. Both hashes have the same amount of keys and same key names. I would like to print them out side by side.
I have come up with:BEST SELECTED BEST best->Key1 kept_best->Key1 Key1->el1 Key1->el1 Key1->el2 Key1->el2 ... best->Key2 kept_best->Key2 Key2->el1 Key2->el1 Key2->el2 Key2->el2 ...
But I find my solution lacking in elegance and wit and wonder if the monks have a better way to do it?.print "BEST SELECTED BEST\n"; foreach my $value (sort keys %{$best}){ my $i = 0; foreach my $bind_energy (@{$best->{$value}}){ printf "%10.5f ", $bind_energy; if (defined($kept_best->{$value}->[$i])){ printf "%10.5f \n", $kept_best->{$value}->[$i]; $i++; } else { print "\n"; } } }
Thanks,
-tomdbs98
|
|---|