in reply to Bit of maths between two files

Oh-- ok. So you need the sum of all x's, sum of all y's, sum of all z's. Seems like you could read them into 3 arrays while you're splitting them, and the add up the elements of each array. Would that work or am I still missing something?

Replies are listed 'Best First'.
Re^2: Bit of maths between two files
by Anonymous Monk on Aug 05, 2004 at 15:34 UTC
    i will have a go at this suggestion, thanks
      Hi!

      Try this:
      my @file = @ARGV; my @coords; foreach $f (@file) { open (FILE, "<$f"); while (<FILE>) { my @line = split(/\s+/,$_); for my $i (0..$#line) { $coords[$i] += $line[$i]; } } close FILE; } print "@coords\n";
      mawe
        thanks for that, in addition how could i adjust this so that it sumsthe first x in file1 with first x in file2?
      have tried the following but no success!
      $file = shift@ARGV; $file2=shift@ARGV; open (FILE, "<$file"); while (<FILE>) { @array = ( ); chomp; ( $x, $y, $z) = split (/\s+/, $_); push @array, $x; $size = @array; } open (FILE2, "<$file2"); while (<FILE2>) { ($x1, $y1, $z1) = split (/\s+/, $_); for ($i=0; $i<$size;$i++) { $sum = $x1+$array[$i]; print $sum; } #print $sum; }