Hello jck, as I look at the code on the link and the code on this node, I see discrepancies. At some point, you can't go back and "fix" the original post, as it appears you're trying to reconcile 2 distance functions which are similar in that they both measure distance, but dissimilar in that they have different variables and indices. It's nothing that can't be ironed out, but at some point, you're gonna have to choose what you're gonna go with, so that we can all be on the same page. Let's take a look at the main control of your (updated?) original post:

for my $i (0 .. $#data) { for my $j (0 .. $#data) { next if $i == $j; my @coords_i = @{$data[$i]}[1,2,3]; my @coords_j = @{$data[$j]}[1,2,3]; print OUT "%s to %s Distance-%.5f\n", ####( ; )?? $data[$i][1], $data[$j][1], $data[$i][11], $data[$j][11], distance(\@coords_i, \@coords_j); } }

We have an explicit double loop, which will allow the ordered enumeration you desire to occur, but I can see that it goes over the entire array twice, which doesn't gybe with the fields at the link you posted. When I run your program, I get this to confirm my suspicion:

C:\Users\Fred\Desktop\pm>perl dis1.pl Argument "CA" isn't numeric in subtraction (-) at dis1.pl line 38, <IN +> line 4 ( #1) (W numeric) The indicated string was fed as an argument to an oper +ator that expected a numeric value instead. If you're fortunate the me +ssage will identify which operator was so unfortunate. Argument "N" isn't numeric in subtraction (-) at dis1.pl line 38, <IN> + line 4 (# 1) Argument "MSE" isn't numeric in subtraction (-) at dis1.pl line 38, <I +N> line 4 (#1) Argument "C" isn't numeric in subtraction (-) at dis1.pl line 38, <IN> + line 4 (# 1) Argument "O" isn't numeric in subtraction (-) at dis1.pl line 38, <IN> + line 4 (# 1) Done.

That's perl saying "you can't subtract strings." You need to adjust your indices. If you showed your actual input, actual script, and actual output between code tags on perlmonks, then I'm pretty sure that your troubles are ephemeral. Other than that, you're not all that far from what you want because the output is well-formed:

%s to %s Distance-%.5f 12NC1%s to %s Distance-%.5f 13NC2%s to %s Distance-%.5f 14NO3%s to %s Distance-%.5f 21CN1%s to %s Distance-%.5f 23CC1%s to %s Distance-%.5f 24CO2%s to %s Distance-%.5f 31CN2%s to %s Distance-%.5f 32CC1%s to %s Distance-%.5f 34CO1%s to %s Distance-%.5f 41ON3%s to %s Distance-%.5f 42OC2%s to %s Distance-%.5f 43OC1

Best of luck and many happy adventures with perl.


In reply to Re^3: XYZ Manipulation by Aldebaran
in thread XYZ Manipulation by jcklasseter

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.