diff options
Diffstat (limited to 'scripts/vyatta-show-interfaces.pl')
-rw-r--r-- | scripts/vyatta-show-interfaces.pl | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/vyatta-show-interfaces.pl b/scripts/vyatta-show-interfaces.pl index 092f147..0ec5d3e 100644 --- a/scripts/vyatta-show-interfaces.pl +++ b/scripts/vyatta-show-interfaces.pl @@ -335,6 +335,39 @@ sub run_reset_intf { } } +sub alphanum_split { + my ($str) = @_; + my @list = split m/(?=(?<=\D)\d|(?<=\d)\D)/, $str; + return @list; +} + +sub natural_order { + my ($a, $b) = @_; + my @a = alphanum_split($a); + my @b = alphanum_split($b); + + while (@a && @b) { + my $a_seg = shift @a; + my $b_seg = shift @b; + my $val; + if (($a_seg =~ /\d/) && ($b_seg =~ /\d/)) { + $val = $a_seg <=> $b_seg; + } else { + $val = $a_seg cmp $b_seg; + } + if ($val != 0) { + return $val; + } + } + return @a <=> @b; +} + +sub intf_sort { + my @a = @_; + my @new_a = sort { natural_order($a,$b) } @a; + return @new_a; +} + # # main @@ -369,6 +402,8 @@ if (! defined $action) { $action = 'show'; } +@intf_list = intf_sort(@intf_list); + my $func; if (defined $action_hash{$action}) { $func = $action_hash{$action}; |