in reply to XYZ Manipulation

Where did you obtain this script?

The first problem is that you are opening your input file:

open(IN, '<', $source) or die "Couldn't open $source: $!\n";

But then trying to read your input from stdin:

my @data = map [ split ], grep /\S/, <>; ### <> reads from stdin (or +a file named on the command line) You would need <IN> instead.

That problem explains why the script "gets stuck and doesn't exit.". It is waiting for input from the command which you aren't supplying.

The bunch of error messages you get when you added the print statement suggest that you forgot to add the ';' at the end of the line.

Try replacing <> with <IN> in this line:

my @data = map [ split ], grep /\S/, <>;
And then either remove the print statement you added; or add the semicolon on the end; then come back to us with your progress.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^2: XYZ Manipulation
by jcklasseter (Sexton) on Jun 15, 2015 at 17:54 UTC
    I obtained parts of it from
    http://stackoverflow.com/questions/20741484/calculating-distance-betwe +en-atoms-by-atomic-coordinates?rq=1
    . <> Replaced. I got error messages with  print ....., as well as  print......, ; as well as their printf deviations. Updated original post with corrections. The getting stuck part makes sense, however. Thanks.

      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.