This method is fundamentally flawed. What happens when two stars have the same distance? Why are you calculating spherical co-ordinates with a cartesian distance? Are you aware that RA (Right Ascension) is measured in hours, (from 0-24), not degrees?
(Updated: Yes, [id://hardburn], technically 0h to 23h 59m 59.999999...s, but I was trying to be lazy.)
On the technical level, you are trying to index your array using a non-integer value $r2 which is much much less than one, so your calls to $foo[$sorted[$r2]] are returning $foo[$sorted[0]]. There are other stylistic issues, but this is your main technical problem.
You would do better to use a hash, as suggested by dpuu ... though for the wrong reason. Even better would be to rotate your coordinates so that your center point is at +90, as then distance becomes simple subtraction. Perhaps Astro::Coords can help?
use Astro::Coords; $c = new Astro::Coords( name => "My center", ra => '05:22:56', dec => '-26:20:40.4', type => 'B1950' units=> 'sexagesimal'); $t = new Astro::Coords( name => "My target", ra => '05:22:56', dec => '26:20:40.4', type => 'B1950' units=> 'sexagesimal'); print $c->distance($t);
In reply to Re: sorting/output
by idsfa
in thread sorting/output
by srkaeppler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |