From bce512bc41bf288fc6f94d3e092f525dd8541345 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Sun, 28 Jul 2002 16:40:00 +0000 Subject: MDK::Common::DataStructure: add sort_numbers --- MDK/Common/DataStructure.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'MDK/Common') diff --git a/MDK/Common/DataStructure.pm b/MDK/Common/DataStructure.pm index f139555..0becc8d 100644 --- a/MDK/Common/DataStructure.pm +++ b/MDK/Common/DataStructure.pm @@ -10,6 +10,10 @@ MDK::Common::DataStructure - miscellaneous list/hash manipulation functions =over +=item sort_numbers(LIST) + +numerical sort (small numbers at beginning) + =item ikeys(HASH) aka I, as simple as C=E $b } keys> @@ -106,10 +110,11 @@ use MDK::Common::Func; use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK); @ISA = qw(Exporter); -@EXPORT_OK = qw(ikeys add2hash add2hash_ put_in_hash member invbool listlength deref deref_array is_empty_array_ref is_empty_hash_ref uniq difference2 intersection next_val_in_array group_by2 list2kv); +@EXPORT_OK = qw(sort_numbers ikeys add2hash add2hash_ put_in_hash member invbool listlength deref deref_array is_empty_array_ref is_empty_hash_ref uniq difference2 intersection next_val_in_array group_by2 list2kv); %EXPORT_TAGS = (all => [ @EXPORT_OK ]); +sub sort_numbers { sort { $a <=> $b } @_ } sub ikeys { my %l = @_; sort { $a <=> $b } keys %l } sub put_in_hash { my ($a, $b) = @_; while (my ($k, $v) = each %{$b || {}}) { $a->{$k} = $v } $a } sub add2hash { my ($a, $b) = @_; while (my ($k, $v) = each %{$b || {}}) { $a->{$k} ||= $v } $a } -- cgit v1.2.1