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
Premature optimization is the root of all job security

In reply to Re: Subtracting two arrays by GrandFather
in thread Subtracting two arrays by HaveANiceDay

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.