the problem that is happening is that when i get an output, it looks like:#!/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 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: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 . . .
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!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 . . .
In reply to sorting/output by srkaeppler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |