|Just another Perl shrine|
Re: Sorting Hash / Arrayby Cristoforo (Deacon)
|on May 16, 2012 at 20:46 UTC||Need Help??|
If each of the quartets was 3 digits long, (010.182.012.000/25, for example), an alphanumeric sort, cmp, would be fine. The Socket module provides a function, inet_aton(), that transforms the quartet into a sortable entity.
I added one more address to test the sort function, (with a key of 36 and value 10.182.2.0/25) Adding this record will show if the sorts are working correctly. It should sort before 10.182.12.0/25 if the sort is correct.
The output is,
If I add the additional line to kcott's code, it gives the following output:
Hope this helps,
Update: I see that johngg beat me to the answer and his explanation of why the lexical sort won't sort correctly and why Socket should be used instaed.