# col1 col2 index
my $sample1 = ['str1 str2 1',
'str3 str4 2',
'str5 str6 3',
'str7 str8 4',
'str9 str10 5'];
my $sample2 = ['str1 str2 0',
'str3 str4 4'];
my $sample3 = ['str1 str2 3',
'str3 str4 4'];
####
$result_spl1 = [
'str1',
'str3',
'str5',
'str7',
'str9',
'str10'
];
$result_spl2 = [
'str1',
'str2',
'str3',
'str4',
];
$result_spl3 = [
'str1',
'str3',
'str4',
];
####
use Data::Dumper;
get_column($sample1);
sub get_column
{
my $ar = shift;
my $all;
foreach my $str ( @{$ar} )
{
my @ar = (split " ",$str)[0,1,2];
push @$all, [ @ar ];
}
my @clean;
my $flag = $all->[0][2]+1;
my $idx;
my $diff;
push @clean, $all->[0][0],$all->[0][1];
foreach my $i ( 1 .. @$all-1 )
{
$idx = $all->[$i][2];
$diff = abs($idx-$flag);
if ( $diff == 1 )
{
push @clean, $all->[$i][1];
}
else
{
push @clean, $all->[$i][0],$all->[$i][1];
}
$flag = $idx;
}
print Dumper \@clean ;
return ;
}