K
Katie
I have this sub, and after the sort, it keeps the last line of simliar
FEATURE lines. However, the first line is the latest version, not the
last line. How can I change to have it keeps the first line instead of
the last line?
------------------------------------------------------------------------------------------------------------------------------
sub lineSort {
($mode, @list) = @_;
local (@sortedList, @cleanList);
@sortedList = sort( @list );
for ( $i = 0; $i < $#sortedList; $i++ ) {
($l1_f1, $l1_f2, $l1_f3, $l1_f4) = split( /[ \t]+/, $sortedList[$i]);
($l2_f1, $l2_f2, $l2_f3, $l2_f4) = split( /[ \t]+/,
$sortedList[$i+1]);
LINESORT: {
if ($mode eq "SERVER" ) { # Compare on 2nd & 3rd fields - name &
hostid
($l1_f2 ne $l2_f2 && $l1_f3 ne $l2_f3) &&
push( @cleanList, $sortedList[$i] );
last LINESORT;
}
if ($mode eq "FEATURE") { # Compare on 2nd field - feature name
( $l1_f2 ne $l2_f2 ) && push( @cleanList, $sortedList[$i] );
last LINESORT;
}
}}
#
# Always save the last line
#
push( @cleanList, $sortedList[$#sortedList] );
@cleanList;
} # lineSort
FEATURE lines. However, the first line is the latest version, not the
last line. How can I change to have it keeps the first line instead of
the last line?
------------------------------------------------------------------------------------------------------------------------------
sub lineSort {
($mode, @list) = @_;
local (@sortedList, @cleanList);
@sortedList = sort( @list );
for ( $i = 0; $i < $#sortedList; $i++ ) {
($l1_f1, $l1_f2, $l1_f3, $l1_f4) = split( /[ \t]+/, $sortedList[$i]);
($l2_f1, $l2_f2, $l2_f3, $l2_f4) = split( /[ \t]+/,
$sortedList[$i+1]);
LINESORT: {
if ($mode eq "SERVER" ) { # Compare on 2nd & 3rd fields - name &
hostid
($l1_f2 ne $l2_f2 && $l1_f3 ne $l2_f3) &&
push( @cleanList, $sortedList[$i] );
last LINESORT;
}
if ($mode eq "FEATURE") { # Compare on 2nd field - feature name
( $l1_f2 ne $l2_f2 ) && push( @cleanList, $sortedList[$i] );
last LINESORT;
}
}}
#
# Always save the last line
#
push( @cleanList, $sortedList[$#sortedList] );
@cleanList;
} # lineSort