in reply to Re^2: Subroutine not correct (I think)
in thread Subroutine not correct (I think)

This piece of code may do something similar what you need.
use strict; use warnings; use diagnostics; sub distance { my ($aa, $bb) = @_; return sqrt(($aa->[0] - $bb->[0])**2 + ($aa->[1] - $bb->[1])**2 + ($aa->[2] - $bb->[2])**2); } my $source = "./CONTCAR"; open(IN, '<', $source) or die "Couldn't open $source: $!\n"; my @data = map [ split ], grep /\S/, <IN>; foreach my $d1 (@data) { foreach my $d2 (@data) { printf "($d1->[0],$d1->[1],$d1->[2]) <-> ($d2->[0],$d2->[1],$d +2->[2]) = %f\n", distance($d1, $d2); } } close IN; print "Done.\n";

Replies are listed 'Best First'.
Re^4: Subroutine not correct (I think)
by jcklasseter (Sexton) on Jun 17, 2015 at 13:38 UTC
    That's so beautiful. Thank you. It is greatly appreciated. I understand the foreach loop a lot better with an example, thanks.