I am working on a perl code that reads in a file with various information
(example: ID, value A, value B, value C..Value Z)
The file values are separated by tabs.
I want to only extract the first 3 columns (ID, value A, value B) and output it to another file, but additionally I want to add a 4th column in the output file that calculates the difference between A and B for each line.
This is the code I have so far:
#!/usr/bin/perl
use strict;
use warnings;
my $input;
my $output;
my ($ID, $A, $B, $DIF);
print "Enter output file name \n";
chomp ($output = <STDIN>);
chomp ($input = "in.txt");
open (IN, $input);
open (OUT, >"$output");
while (<IN>){
chomp;
($ID, $A, $B) = split ("\t");
#push @_, ($DIF = $B-$A);
print OUT "$ID\t$A\t$B\t$DIF\n";
}
close (IN);
close (OUT);
I am stuck with trying to figure out how to code the calculation for the 4th column...
I tried using
push @_, ($DIF = $B-$A);
but it gives me the error that A and B is not numeric when it reads the header in the original file. Any help is appreciated!