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);

The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. -- Cyrus H. Gordon

In reply to Re: sorting/output by idsfa
in thread sorting/output by srkaeppler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.