Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Subroutine not correct (I think)

by pme (Prior)
on Jun 17, 2015 at 13:31 UTC ( #1130804=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1130804]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2020-01-23 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?