Gents;
Given an array such as @Array1 = (1, 3, 5, 7, 9);
and a search argument of '4', I am trying to locate the element on @Array1 that is closest to yet less than or equal to the search argument and return the proper index value.
While searching for exact matches using various methods including loops and greps seem to be quite easy, searching for the condition stated above is proving to be frustrating.
Perhaps someone can review my snippet below and advise on a workable method to accomplish this?
===Begin Snippet===
my $index = 0;
my @Array1 = ('1', '3', '5', '7', '9');
my $Argument = "4";
my $Last_Index = 0;
$index=$#Array1;
while($index >= 0) {
if ($Array1[$x] le $Argument) {
last;
}
$Last_Index = $index
$index--;
}
===End Snippet===
Thanks all...
Given an array such as @Array1 = (1, 3, 5, 7, 9);
and a search argument of '4', I am trying to locate the element on @Array1 that is closest to yet less than or equal to the search argument and return the proper index value.
While searching for exact matches using various methods including loops and greps seem to be quite easy, searching for the condition stated above is proving to be frustrating.
Perhaps someone can review my snippet below and advise on a workable method to accomplish this?
===Begin Snippet===
my $index = 0;
my @Array1 = ('1', '3', '5', '7', '9');
my $Argument = "4";
my $Last_Index = 0;
$index=$#Array1;
while($index >= 0) {
if ($Array1[$x] le $Argument) {
last;
}
$Last_Index = $index
$index--;
}
===End Snippet===
Thanks all...