This may, at least, get you started:

use strict; use warnings; my $valuesFile = 'file.txt'; my (@points, $count); my @keys = qw(A X Y Z); open FH, $valuesFile or die "Can't open $valuesFile: $!"; while(<FH>){ chomp; my %pointHash; $pointHash{$keys[$count++]} = $_ for (split)[0, 2..4]; push @points, \%pointHash; $count=0; } close FH or die "Can't close $valuesFile: $!"; my @results; for my $x(0..$#points){ my $p1 = $points[$x]; for my $y (0..$#points){ my $p2 = $points[$y]; my $dist = sqrt(abs(( $p1->{X} - $p2->{X} ) **2 + ( $p1->{Y} - $p2->{Y} ) **2 + ( $p1->{Z} - $p2->{Z} ) **2)) ; $results[$x][$y] = sprintf("%.0f", $dist); } } #------------------- print "\t"; print "$points[$_]->{A}\t" for(0..$#points); print "\n"; $count = 0; for my $r (@results){ print "$points[$count++]->{A}\t"; printf "%.0f\t",$_ for @$r; print "\n"; }

Output:

A B C A 0 4 5 B 4 0 4 C 5 4 0

Hope this helps!


In reply to Re: reading a text file and accepting input by Kenosis
in thread reading a text file and accepting input by doozy

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.