
shawnhcorey
Enthusiast

Oct 1, 2008, 6:18 AM
Post #4 of 16
(3059 views)
|
|
Re: [Anu Singh] calculate distance using values in an array
[In reply to]
|
Can't Post
|
|
hello, Its between two points but iteratively, for ex: its between row1_row2, row1_row3, row1_row4..... so on.... and then it shud be row2_row3, row2_row4, row2_row5......so on till row6_row7.. so i think we shud write a for loop which looks something like this for($AAi = 1; $AAi<= 7; $AAi++){ for ($AAj = 2; $AAj<= 7; $AAj++){ then calculate distance using my $dist = sqrt(($Xi-$Xj)**2+($Yi-$Yj)**2+($Zi-$Zj)**2) it is supposed to be something like this...
#!/use/bin/perl use strict; use warnings; use Data::Dumper; my @points = (); open(IN, "/Users/anu/out.pl") or die "$!"; while (my $line = <IN>) { chomp($line); my @array = (split (/\s+/, $line))[6, 7, 8]; print "@array\n"; push @points, [ @array ]; } close(IN); print '@points : ', Dumper \@points; for my $i1 ( 0 .. $#points -1 ){ my ( $x1, $y1, $z1 ) = @{ $points[$i1] }; for my $i2 ( 1 .. $#points ){ my ( $x2, $y2, $z2 ) = @{ $points[$i2] }; my $dist = sqrt( ($x2-$x1)**2 + ($y2-$y1)**2 + ($z2-$z1)**2 ); print "distance from ( $x1, $y1, $z1 ) to ( $x2, $y2, $z ) is $dist\n"; } } __END__ I love Perl; it's the only language where you can bless your thingy. Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib. Get Markup Help. Please note the markup tag of "code".
|