Think about Loose Coupling | |
PerlMonks |
Re^3: find closest element of array without going overby starbolin (Hermit) |
on Jun 27, 2008 at 00:24 UTC ( [id://694299]=note: print w/replies, xml ) | Need Help?? |
Except I see at least five errors in your code. Very interesting indexing into an array with a float. I know perl will DWIM but although perl will round toward 0, I don't think it's guaranteed. I'm being picky here because the code illustrates that a quick-search is difficult to write correctly. Your code makes my point perfectly, thank you. Update: Three is a Red Herring. When first I looked at your code I said "Ah, there is the Binary-Search-Overflow bug!" But of course this was a bigger problem when long was the memory space and int was shorter than long. But Perl is written so that an int can access the total memory space and so three is less of a bug that any other operation on large integers would be. s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}
In Section
Seekers of Perl Wisdom
|
|