in reply to Bit of maths between two files

This sounds like a homework problem. Can you show us some code so we know you at least gave it some thought?

Replies are listed 'Best First'.
Re^2: Bit of maths between two files
by Anonymous Monk on Aug 05, 2004 at 15:03 UTC
    Gone past my best of homwork problems, just trying to pick up perl.
    $file = shift@ARGV; $file2=shift@ARGV; open (FILE, "<$file"); while (<FILE>) { ( $x, $y, $z) = split (/\s+/, $_); } open (FILE2, "<$file2"); while (<FILE2>) { ( $x1, $y1, $z1) = split (/\s+/, $_); } open (OUT, ">output"); print OUT $x $y $z $x1 $y1 $z1; ###then do maths

      Looking at what you've done so far, you're basically there. Perhaps you're confused about how to output a properly formatted line? The last print statement you have will create an output file with no separation between the numbers (and no newline at the end). There are a number of ways (of course) to get it properly formatted. Some examples:

      print OUT "$a $b $c\n"; printf OUT "%d %d %d\n", $a, $b, $c; print OUT join(' ',$a, $b, $c), "\n";

      The latter two will work better if you are going to do the addition inline, e.g.:

      printf OUT "%d %d %d\n", $x+$x1, $y+$y1, $z+$z1;

      Brad