in reply to Re^2: re-key a hash
in thread re-key a hash
If we're using multiple statements anyway (not doing so was the point of my obscure ditty), I'd shuffle things around.
{ my @key = sort { $a <=> $b } keys %h; @h{ 0 .. $#key } = delete @h{ @key }; }
That seems like a cleaner separation of concerns. The symmetry of the second line here seems more pleasing and makes it more robust — it remains valid regardless of how the list of keys is generated.
Makeshifts last the longest.
|
|---|