in reply to Subtracting two arrays
The code you posted didn't generate the output you posted because there were a bazillion syntax errors. The following code fixes the syntax errors and possibly generates the result you want. The key issue was assigning your results to $Delta which is a different variable to the array @Delta.
#!/usr/bin/perl use strict; use warnings; my @Molecule_01 = ( ['C', 0.2565522, -1.5308230, 0.0000000], ['C', -0.8038556, -0.7047550, 0.0000000], ['C', -0.8519687, 0.7637319, 0.0000000], ['C', 0.3236482, 1.5968480, 0.0000000], ); my @Molecule_02 = ( ['C', 0.3916152, -1.5774692, 0.0000000], ['C', -0.8180007, -0.7937790, 0.0000000], ['C', -0.8314989, 0.6754852, 0.0000000], ['C', 0.1934963, 1.5451038, 0.0000000], ); my @Delta; for my $i (0 .. $#Molecule_01) { my $row = $Molecule_01[$i]; my @rowResults; push @rowResults, $Molecule_01[$i][0]; for my $j (1 .. $#{$row}) { push @rowResults, $Molecule_01[$i][$j] - $Molecule_02[$i][$j]; } push @Delta, \@rowResults; } print "@$_\n" for @Delta;
Prints:
C -0.135063 0.0466461999999999 0 C 0.0141451 0.089024 0 C -0.0204698 0.0882467 0 C 0.1301519 0.0517441999999999 0
|
|---|