Hi,
I have a code (below) that reads from a file and output the file content a fter inserting a tab and & in-between different elements into another file.
my $REPORT_FILE = 'report.txt';
$allRfile = 'AllidentifiedMetabs1.txt';
open(ALL,"<AllidentifiedMetabs1.txt") || die "can't open $allRfile $!";
my $line = <ALL>;
($ID,$name,$M2, $M3, $M4, $M5) = split /\t/, $line;
@all = ($ID,$name,$M2, $M3, $M4, $M5);
#chomp @all;
close ALL;
open(OUT, "+>report.txt") or die "Can't open data";
foreach $a(@all) {
print "$ID & $name & $M2 & $M3 & $M4 & $M5";
};
Input example- a txt file:
1 Sugar 3.13E-01 4.38E-01 4.38E-01 2.19E-01
2 Histidine 6.25E-02 1.88E-01 6.25E-02 6.25E-02
Output required:
1 & Sugar & 3.13E-01 & 4.38E-01 & 4.38E-01 & 2.19E-01
2 & Histidine & 6.25E-02 & 1.88E-01 & 6.25E-02 & 6.25E-02
I would be happy if someone helps.
Thanks