http://qs321.pair.com?node_id=11106882

IB2017 has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

Updated

My array contains a set of coordinates indices in the form of "x.x" (coming from a Tk Text widget), being the first value the row and the second the character position. Any two elements of the array represents a couple, i.e. start and end points in a text (element 0 and 1, element 2 and 3, and so forth). An example is:

my @array = (1.1,1.4,5.33,6.1,7.23,7.133,10,11);

Given a coordinate index, I need to find the range (start end point) in which the coordinate index falls. So, for example, given 1.3, I need to find the range 1.1-1.4, i.e. element 0 and element 1 of my array. I have a small (and verbose) script that can find a range if the array is of natural numbers, but it fails with coordinates indices like mine since, in my example, 7.23 is considered bigger than 7.133 (however, in terms of indices the opposite is the truth). Is there a straightforward way to do comparisons of my indices?

use strict; use warnings; my @array = (1.1,1.4,5.33,6.1,7.23,7.133,10,11); print "\nenter number\n"; chomp (my $cursorPosition = <STDIN>); my $itr=0; foreach my $tagBegin (@array){ if (0 == $itr % 2) { } else{ last if $cursorPosition <= $tagBegin; } $itr++; } print "Range is $array[$itr-1] - $array[$itr]";

With the above script, given coordinate 7.25 it finds the wrong range.