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";
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|