If there are going to be many helices, I'd use a hash of hashes, where each element is an array reference:

$atoms{HELIX1}{A} = [ ( -1.115, 8.537, 7.075)];
#!perl use warnings; use strict; my %atoms; my $key; while(<DATA>) { chomp; next if /^\s*$/; if(/^[^\s]/){ s/:.*$//; $key = $_; print "\$_: $_\n","\$key: $key\n"; } else{ s/^\s*|\s*$//g; (my $sub, my $idx,my $x, my $y,my $z) = split(/\s+/,$_,5); print "\t\$_: $_\n","\t\$sub: $sub\n\txyz",join(", ", ($x, $y, + $z)),"\n"; $atoms{$key}{$sub} = [ (+$x, +$y, +$z)]; # force numerical con +text } } __DATA__ HELIX1: x y z A 1 -1.115 8.537 7.075 B 2 -2.745 5.280 7.165 C 3 -0.777 3.267 7.329 D 4 1.610 5.225 10.885 E 5 0.296 5.263 10.912 HELIX2: K 1 -0.696 13.041 22.357 L 2 1.152 11.081 23.082 M 3 2.200 17.590 18.424

While the above code is, doubtless, is less elegant and otherwise inferior to what those monks more fluent in Perl than I would write, it will process a small amount of data (say a few thousand points). Now, why would your assignment be to calculate the square of the distance: R2 = ∑(xi − xj)2?

Do you really mean: R = √∑(xi − xj)2?

emc

" The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents."
—Nathaniel S. Borenstein

In reply to Re: confused with distances by swampyankee
in thread confused with distances by Anonymous Monk

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.