System information
--- view.pl 2001/06/23 01:35:28 1.1
+++ view.pl 2001/10/11 15:21:22 1.2
@@ -75,6 +75,31 @@
exit;
+sub alphanumerically {
+ local($&, $`, $', $1, $2, $3, $4);
+ # Sort numbers numerically
+ return $a cmp $b if $a !~ /\D/ && $b !~ /\D/;
+ # Sort IP addresses numerically within each dotted quad
+ if ($a =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
+ my($a1, $a2, $a3, $a4) = ($1, $2, $3, $4);
+ if ($b =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
+ my($b1, $b2, $b3, $b4) = ($1, $2, $3, $4);
+ return ($a1 <=> $b1) && ($a2 <=> $b2)
+ && ($a3 <=> $b3) && ($a4 <=> $b4);
+ }
+ }
+ # Handle things like Level1, ..., Level10
+ if ($a =~ /^(.*\D)(\d+)$/) {
+ my($a1, $a2) = ($1, $2);
+ if ($b =~ /^(.*\D)(\d+)$/) {
+ my($b1, $b2) = ($1, $2);
+ return $a2 <=> $b2 if $a1 eq $b1;
+ }
+ }
+ # Default is to sort alphabetically
+ return $a cmp $b;
+}
+
sub editRow {
my %args = @_;
my $table = $args{table};
@@ -95,7 +120,7 @@
if ( $edit ne "delete" ) {
if ( $row eq "add" and $edit eq "true" ) {
- foreach $key (sort(keys %table_data)) {
+ foreach $key (sort alphanumerically (keys %table_data)) {
if ( not defined $tmp ) { $tmp = $table_data{$key}; }
}
}
@@ -103,7 +128,7 @@
$tmp = $table_data{$row};
}
# need to get a row to build the menu.
- foreach $field (sort(keys %$tmp)) {
+ foreach $field (sort alphanumerically (keys %$tmp)) {
$table_data{$row}{$field} = $FORM{$field};
#print STDERR returnTime." editRow, field=$field row=$row table=$table_data{$row}{$field}\n";
}
@@ -168,7 +193,7 @@
}
}
$i = 0;
- foreach $head (sort (keys %$tmp_key)) {
+ foreach $head (sort alphanumerically (keys %$tmp_key)) {
$headers[$i] = $head;
++$i;
}
@@ -250,7 +275,7 @@
cssTableStart("white");
#Display each data Row
- foreach $key ( sort (keys %table_data) ) {
+ foreach $key ( sort alphanumerically (keys %table_data) ) {
print "\n";
++$counter;
++$pass;
@@ -267,7 +292,7 @@
}
$i = $c;
NMIS - Network Management Information System http://www.sins.com.au/nmis/
31 of 43 15/04/2002 3:59 PM