in reply to Perl hashes and non-determinism
The values might not be unique but the keys certainly are. Sort by value first and then by key - that will give you a deterministic order. This is essentially what you have aimed for in your "inelegant" solution. The downside there is that you are sorting all the keys when it is only those with identical values which actually need it. I'd prefer to use something like
foreach my $k sort { $hash{$a}{value} <=> $hash{$b}{value} || $a cmp $b} (keys %hash)Does this seem more elegant to you?
🦛
|
|---|