hello
I am trying to loop through an array and pick out only individual values.
The following code i wrote works but misses a value in the middle of the array for some reason. I have tried a few things but I can't find why it misses this particular value.
The array values are;-
0801
1001
0301
0801
0601
0701
0701
0701
0701
0701
0701
0701
and the array is called @omonths
here is the code;-
@sortedomonths = sort @omonths;
for($i=0;$i<@sortedomonths;$i++) {
if ($sortedomonths[$i] eq $sortedomonths[$i+1]) {$i+=1;}
else {push @indmonths, $sortedomonths[$i];}
}
the results of a print command produce this;-
0301
0601
0701
1001
as you see 0801 is missing, but I can't figure out why.
Any help would be great.
Cheers
Jez

I am trying to loop through an array and pick out only individual values.
The following code i wrote works but misses a value in the middle of the array for some reason. I have tried a few things but I can't find why it misses this particular value.
The array values are;-
0801
1001
0301
0801
0601
0701
0701
0701
0701
0701
0701
0701
and the array is called @omonths
here is the code;-
@sortedomonths = sort @omonths;
for($i=0;$i<@sortedomonths;$i++) {
if ($sortedomonths[$i] eq $sortedomonths[$i+1]) {$i+=1;}
else {push @indmonths, $sortedomonths[$i];}
}
the results of a print command produce this;-
0301
0601
0701
1001
as you see 0801 is missing, but I can't figure out why.
Any help would be great.
Cheers
Jez