[padb] r412 committed - When sorting entries for the proc-summary report check if all...

padb at googlecode.com padb at googlecode.com
Mon Nov 8 18:18:32 GMT 2010


Revision: 412
Author: apittman at gmail.com
Date: Mon Nov  8 10:16:16 2010
Log: When sorting entries for the proc-summary report check if all
values are numeric, if so do a numeric sort, if they aren't then
do a text sort.

http://code.google.com/p/padb/source/detail?r=412

Modified:
  /trunk/src/padb

=======================================
--- /trunk/src/padb	Mon Nov  8 10:13:19 2010
+++ /trunk/src/padb	Mon Nov  8 10:16:16 2010
@@ -3834,11 +3834,29 @@
      my $carg = shift;
      my $key  = shift;
      my @all  = (@_);
+
+    my $numeric = 1;
+
+    foreach my $a (@all) {
+        if ( not $a->{$key} =~ m{\A\d+\z} ) {
+            $numeric = 0;
+            last;
+        }
+    }
+
+    my @sorted;
+
+    if ($numeric) {
+        @sorted = sort { $a->{$key} <=> $b->{$key} } @all;
+    } else {
+        @sorted = sort { $a->{$key} cmp $b->{$key} } @all;
+
+    }

      if ( $carg->{reverse_sort_order} ) {
-        return ( reverse sort { $a->{$key} <=> $b->{$key} } @all );
+        return ( reverse @sorted );
      } else {
-        return ( sort { $a->{$key} <=> $b->{$key} } @all );
+        return (@sorted);
      }
  }





More information about the padb-devel mailing list