in reply to Calc distance between atoms in pdb file

Here's a somewhat simpler and more idiomatic version of your code that does the same thing that may help you. Ask about anything you do not understand:

#!/usr/bin/perl -w use strict; my( @arrayx, @arrayy, @arrayz ); while (<>) { # Find x, y, z coordinates and store in separate arrays if ($_ =~ /^ATOM/) { my @line = $_ =~ m/^(.....).(.....).(....).(...)..(....)....(. +.......)(........)(........)/; ## using push mean you don't have to count because ... push @arrayx, $line[5]; push @arrayy, $line[6]; push @arrayz, $line[7]; } } close *ARGV; ## prevent confusing error message suffixes # Calculate distance between all atom coordinates ## ... $#xxx gives you the highest index in array @xxx foreach my $i ( 0 .. $#arrayx ) { foreach my $j ( $i + 1 .. $#arrayx ) { my $dist = sqrt( ($arrayx[$i] - $arrayx[$j])**2 + ($arrayy[$i] - $arrayy[$j])**2 + ($arrayz[$i] - $arrayz[$j])**2 ); ## Adding $i and $j to your output will let you know what that + output is. print "$i <> $j : $dist\n"; } }

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".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: Calc distance between atoms in pdb file
by Anonymous Monk on Nov 14, 2016 at 11:06 UTC
    I'm getting an error of uSE OF UNINITIALIZED VALUE IN SUBTRACTION AT LINE 47
    foreach my $i ( 0 .. 1520) { foreach my $j ( $i + 1 .. 1520 ) { my $dist = sqrt( ($arrayx[$i] - $arrayx[$j])**2 + ($arrayy[$i] - $arrayy[$j])**2 + ($arrayz[$i] - $arrayz[$j])**2 ); ## Adding $i and $j to your output will let you know what that print "$i <> $j : $dist\n"; } } exit 0;
      Where do the 1520 come from? Obviously not from the originally posted code.
        I took the value to $count-1 ... that is where 1520 came from
Re^2: Calc distance between atoms in pdb file
by Anonymous Monk on Nov 14, 2016 at 15:58 UTC
    I'm Still getting Use of uninitialized value in subtraction