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:
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:@users = sort { $::a->{count} <=> $::b->{count} } @users;
my $a = 'john'; @users = sort { $a->{count} > $b->{count} } @users;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Sorting data structure
by davido (Cardinal) on Oct 14, 2005 at 05:52 UTC | |
|
In Section
Seekers of Perl Wisdom