http://qs321.pair.com?node_id=500126


in reply to Sorting data structure

The variable users, as used in the original post, represents a hash, not an array. This we know from the brace after the -> infix operator; therefore, assuming numerical comparison, the answer to the original question is this:
@users = sort { $::a->{count} <=> $::b->{count} } @users;
I favor the addition of :: to ensure that $a and $b remain global. This would have made a difference if the comparison was performed using the greater operator, >, and $a was lexical. For example, this will not work:
my $a = 'john'; @users = sort { $a->{count} > $b->{count} } @users;