Some further suggestions. It would be fitting to hold point coordinates in an array type variable. Instead of ($Znx, $Zny, $Znz), a single @Zn variable might be used.

Secondly, regular expressions offer a convenient method to capture specific parts of input. This allows one to write, e.g. @Zn = ($1, $2, $3); — but you must include (...) groups in the pattern. If the data is of rigidly fixed format, pack() and unpack() are often quite useful:

my $xyz_fmt = '@30a7 @38a6 @46a6'; while ($pdbline = <IN>) { if ($pdbline =~ m/ZN1 LG1 X/) { @Zn = unpack $xyz_fmt, $pdbline; next; } if ($pdbline =~ /^ATOM.*(OD2 ASP|NE2 HIS)/) { push @Atoms, [unpack $xyz_fmt, $pdbline]; ... } } # ... do the calculations once we have all data.
Note that the above example looks a bit strange because of the mixed regex and unpack usage. The second regex here combines three patterns from original code. @Atoms is an array of arrays (AoA). You can check the number of points with int(@Atoms).

Update: for questions regarding the handling of AoA, please see perllol or perldsc.


In reply to Re: calculate distance between atoms and a target atom by oiskuu
in thread calculate distance between atoms and a target atom by mishimakaz

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.