如何两次排序
#!/usr/bin/perl
use strict;
use warnings;
my @int=qw(GigabitEthernet2/4 GigabitEthernet1/1 GigabitEthernet1/15 GigabitEthernet1/2);
my @sort=sort @int;
my @sort2=sort method @sort;
print "\@int is : @int\n";
print "\@sort is : @sort\n";
print "\@sort2 is : @sort2\n";
sub method{
my $num1;
my $num2;
my $pre1;
my $pre2;
my $cnt=0;
if ( $a =~ m/\//){
$pre1=$`;
$num1=$';
$cnt++;
}else {
$num1=$a;
}
if ( $b =~ m/\//){
$pre2=$`;
$num2=$';
$cnt++;
} else {
$num2=$b;
}
print "\$a is :$a\n";
print "\$b is :$b\n";
print "\$num1 is :$num1\n";
print "\$num2 is :$num2\n";
print "\$pre1 is :$pre1\n";
print "\$pre1 is :$pre2\n";
if ($pre1 eq $pre2) {
print "ok\n";
if ( $num1 < $num2 ){
print "1\n";
-1
} elsif ( $num1 > $num2 ){
print "2\n";
1
} else{
print "0\n";
0
}
} else {
print "not ok\n";
0
}
}
阅读(1203) | 评论(0) | 转发(0) |