Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: Find range in coordinates array

by haukex (Archbishop)
on Oct 01, 2019 at 18:29 UTC ( [id://11106918]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Find range in coordinates array (updated)
in thread Find range in array with indices

I cannot match anything if I search for the following value with 3 digits after the "."

With the code I showed, it works for me for values such as my $input = 7.111; (that are actually in the range 7.023-7.133). So if that's not working for you, perhaps you could show an SSCCE?

If you're getting the "Input too wide" error, then probably your @array only contains values with two digits after the decimal point or less and the code is adapting $maxlen (the maximum number of digits after the decimal) to that automatically. You could also do something like "$maxlen should always be at least three digits, or one digit longer than the values in @array, whichever is bigger" by saying my $maxlen = 1 + max 2, map ..., or you could just use a fixed $maxlen.

Replies are listed 'Best First'.
Re^4: Find range in coordinates array (updated)
by IB2017 (Pilgrim) on Oct 01, 2019 at 20:40 UTC

    I had a closer look at your code. Even if there are some aspects I still do not quite understand, I can confirm that it works brilliantly, even better than I first thought. I have tested it with real (a lot of) data. Simply perfect.

      Glad to help, and please feel free to ask :-) You can add the same debugging statements as in my first piece of code (at the bottom of the post), then you can hopefully see how everything is being transformed. If I were to nitpick my own code, I would probably add some checking that all the inputs are in the expected formats (e.g. use a regex instead of split). And the updated piece of code depends on the original array not changing, since it creates a second list of indicies.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11106918]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-16 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found