in reply to Re^2: Save the resultant of " hash sorted by values "
in thread Save the resultant of " hash sorted by values "
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)}.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Save the resultant of " hash sorted by values "
by ikegami (Patriarch) on Mar 23, 2011 at 22:27 UTC | |
by wind (Priest) on Mar 23, 2011 at 22:43 UTC |