For When You Can't Have The Real Thing
[ start | index | login ]
start > perl > sort dictionary by values

sort dictionary by values

Created by dave. Last edited by dave, 16 years and 177 days ago. Viewed 4,011 times. #3
[diff] [history] [edit] [rdf]

Sort A Dictionary By Values

Smallest to largest:

@Keys = sort { $Hash{$a} <=> $Hash{$b} } keys %Hash;

Then iterate over @Keys.

Reverse $a and $b for largest to smallest.

no comments | post comment
This is a collection of techical information, much of it learned the hard way. Consider it a lab book or a /info directory. I doubt much of it will be of use to anyone else.

Useful: | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt