I have taken the liberty to move the opening of the files out of the while loop, because it seems inefficient to open the file each time you get a match, but it really depends on you data (how often it matches).use strict; use warnings; my ($mio, $mio2); my $filename = '/Users/Pabli/Desktop/do_human_mapping.gmt'; my $match = 'DOID:2055'; unlink ("myoutputfilename3.txt"); unlink ("myoutputfilename4.txt"); open(my $file, '<', $filename) or die "open: $!"; open my $out_file3, '>', 'myoutputfilename3.txt' or die "$!"; open my $out_file4, '>', 'myoutputfilename4.txt' or die "$!"; while (<$file>){ my ($name,$id,@genes) = split /\t/; if ($id eq $match) { $mio= join("\n",@genes); print $mio."\n"; print $out_file3 $mio."\n"; # print sul file } if (grep/^$match$/, @genes){ $mio2=$id; print $mio2."\n"; print $out_file4 $mio2."\n"; # print sul file } }
In reply to Re: Unify two files
by Laurent_R
in thread Unify two files
by pabla23
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |