in reply to Re: Sort Hash by Size of the Arrays it References
in thread Sort Hash by Size of the Arrays it References
The only thing I would add is that my personal taste is to mention explicitly when I am using arrays in scalar context. A newbie^W^WSomeone looking at that code might wonder whether entire arrays were being compared, and if so, how?
Saying sort { scalar @{$hash{$a}} <=> scalar @{$hash{$b}} } keys %hashprovides a more explicit idea of what is going on, the fact that the number of elements in the arrays are being compared. Hmm, of course the person might not realise that an array in scalar context gives the number of elements, but at least the scalar keyword gives them some to ponder and hopefully understand.
|
|---|