in reply to Sort assoc array

Associative arrays (ie, hashes) are destined to always being unsorted unless you tie them. But that carries with it serious limitations. The best solution is usually to not care what order the hash's elements are in, but rather, iterate over its keys in a sorted order. Sorting the keys is as simple as:
my @sorted = sort keys %hash;
Or in the context of a loop:
foreach my $key (sort keys %hash) { # Do something with $hash{key}; }

You can also sort the keys by the value they point to...

my @sortedkeys = sort { $hash{$a} cmp $hash{$b} } keys %hash;

The point is, that you pretty much want to think in terms of unsorted hashes with (when needed) a list of sorted keys.

See sort, and perldata.


Dave


"If I had my life to do over again, I'd be a plumber." -- Albert Einstein