hey monks- I am trying to write a program for a database of stars that will sorted by radial distance from the center coordinate. So let me show the code

#!/usr/local/bin/perl -w open (INPUT, "ngc188.catal") || die "died opening input\n"; open (STDOUT, ">sortedngc") || die "died opening output\n"; $n =0; while ($inline = <INPUT> ) { @firstline = split(/\s+/, $inline); ######################################### $pi = 3.141592654; $cos = cos(($firstline[3] * $pi) / 180); $x = abs(($firstline[2]* $cos) - (11.083333 * cos((85.315 * $pi) / 180 +))); $x2 = $x * $x; #squaring the x-xo term $y = abs($firstline[3] - 85.3150000); $y2 = $y * $y; #squaring the y-yo term $r2 = $y2 + $x2; #distance in decimal degree ########################variable definition########################### +## $id[$r2] = $firstline[1];#id $ra[$r2] = $firstline[2];#RA $dec[$r2] = $firstline[3];#dec $prob[$r2] = $firstline[11];#probablity $mag[$r2] = $firstline[12];#magnitude $bv[$r2] = $firstline[13];#b-v ###################################pushing######################## push (@dist, $r2); $n++; } sub numerically { $a <=> $b}; @sorted = sort numerically @dist; @nindex = (0..$n-1); foreach $i (@nindex) { print STDOUT "$id[$sorted[$i]] $ra[$sorted[$i]] $dec[$sorted[$i]] +$prob[$sorted[$i]] $mag[$sorted[$i]] $bv[$sorted[$i]] $sorted[$i]\n"; }
the problem that is happening is that when i get an output, it looks like:
9596 13.4454218 85.0299299 0 17.256 0.907 1.19274490573905e-06 9596 13.4454218 85.0299299 0 17.256 0.907 7.9866617413342e-06 9596 13.4454218 85.0299299 0 17.256 0.907 1.43567635042601e-05 9596 13.4454218 85.0299299 0 17.256 0.907 1.87711214620725e-05 9596 13.4454218 85.0299299 0 17.256 0.907 3.03218139005967e-05 9596 13.4454218 85.0299299 0 17.256 0.907 3.45815761885486e-05 9596 13.4454218 85.0299299 0 17.256 0.907 3.59984633166351e-05 9596 13.4454218 85.0299299 0 17.256 0.907 7.01615131685114e-05 9596 13.4454218 85.0299299 0 17.256 0.907 9.57233947085147e-05 9596 13.4454218 85.0299299 0 17.256 0.907 9.70028702157815e-05 9596 13.4454218 85.0299299 0 17.256 0.907 9.78283014973695e-05 9596 13.4454218 85.0299299 0 17.256 0.907 9.99000064463008e-05 . . .
the code continues to repeat in this format, where, as one will notice the last column is changing in decending order which is good. But what i would like are the values for the different variables(such as $ra, $dec) to correspond to that particular distance value($r2)(which is the last column of the output) so for example:

0043 13.35673 85.10234 0 17.256 0.245 1.19274490573905e-06 0521 13.89567 85.987636 0 12.234 0.907 7.9866617413342e-06 1000 13.235678 85.985463 0 18.314 0.907 1.43567635042601e-05 . . .
So that is what i want, is to have each different value corresponding to a particular distance(which is the last column) Now I have been wondering if perhaps i am not storing the values anywhere in the "while loop" for the program to pull from later on to eventally line things up with. the 9596 term is the last term in the loop iteration. This is why i suspect that the loop terms are not being stored anywhere, but my program is pulling from the last term of the iteration. If you can help me, that would be good. also i may need to clarify what i am saying, so if so, let me know, and ill reply with something more specific. thank you!

In reply to 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.