Dear Perl users,
I need your help to solve my problem below.
I want to print the sequence number without missing number within the range.
E.g. my sequence number :
1 2 3 4 5 6 7 8 11 12 13 14
my desired output:
1 -8 , 11-14
my code below but still problem with the result:
1 - 14
1 - 14
1 - 14
1 - 14
1 - 14
1 - 14
1 - 14
1 - 8
11 - 14
1 - 14
1 - 14
######Perl Code ######
#!/usr/bin/perl -w
use strict;
my $i;
my $start;
my @lst_array = qw /1 2 3 4 5 6 7 8 11 12 13 14/;
$start = $lst_array[0];
for ($i=1; $i<$#lst_array; $i++){
if (($lst_array[$i] - $start) == 1){
print "$lst_array[0] - $lst_array[$#lst_array]\n";
}
elsif (($lst_array[$i] - $start) > 1){
print "$lst_array[0] - $start\n";
print "$lst_array[$i] - $lst_array[$#lst_array]\n";
}
$start = $lst_array[$i];
}
Thank alot
Regards
Mandai