remove WebGUI::Utility::sortHashDescending

This commit is contained in:
Graham Knop 2010-08-20 12:44:40 -05:00
parent c1132e4298
commit a0a26da3bc
2 changed files with 1 additions and 26 deletions

View file

@ -23,7 +23,7 @@ use Net::CIDR::Lite;
our @ISA = qw(Exporter);
our @EXPORT = qw(&isInSubnet
&sortHashDescending &sortHash &isIn &randint &round &scalarEquals
&sortHash &isIn &randint &round &scalarEquals
);
@ -43,7 +43,6 @@ This package provides miscellaneous but useful utilities to the WebGUI programme
$integer = randint($low,$high);
$rounded = round($number, $digits);
%hash = sortHash(%hash);
%hash = sortHashDescending(%hash);
=head1 METHODS
@ -211,27 +210,5 @@ sub sortHash {
return %newHash;
}
#-------------------------------------------------------------------
=head2 sortHashDescending ( hash )
Sorts a hash in decending order by its values. Returns a Tie::IxHash.
You must assign this to a similarly tied hash to preserve the order.
=head3 hash
A hash to be sorted.
=cut
sub sortHashDescending {
my %hash = @_;
tie my %newHash, 'Tie::IxHash';
for my $key ( sort { $hash{$b} cmp $hash{$a} } keys %hash ) {
$newHash{ $key } = $hash{ $key };
}
return %newHash;
}
1;

View file

@ -47,9 +47,7 @@ is(WebGUI::Utility::round(47.6, 0), 48, 'round() - rounds up, too');
tie my %hash2, 'Tie::IxHash';
tie my %hash3, 'Tie::IxHash';
%hash2 = WebGUI::Utility::sortHash(%hash1);
%hash3 = WebGUI::Utility::sortHashDescending(%hash1);
is_deeply([keys %hash2], [qw/e c b d a/], 'sortHash');
is_deeply([keys %hash3], [qw/a d b c e/], 'sortHashDescending');
}
#####################################################################