I feel your nitpicking, but fair enough. :) Yes, the point is that he's not sorting on the correct values (most likely) and he can certainly use a function to translate the keys just as well as using a ST. I personally would prefer to keep the code in one place given this is just an example though.
Also, your function doesn't actually work as is. Fixed:sub ip_to_key { join '', map {sprintf "%03d", $_} split /\./, $_[0] }
Finally, thanks for sharing the pack method of doing a ST as it is definitely snazzier. I use it sometimes as well, but don't feel that it's as immediately decypherable by coders learning about sorts. Although, certainly the easiest method would probably be the functional translation sort {func($a) cmp func($b)}.
In reply to Re^3: Save the resultant of " hash sorted by values "
by wind
in thread Save the resultant of " hash sorted by values "
by sundeep
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |