in reply to Unify two files
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 } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unify two files
by pabla23 (Novice) on Nov 10, 2014 at 11:59 UTC | |
by poj (Abbot) on Nov 10, 2014 at 13:13 UTC | |
by pabla23 (Novice) on Nov 10, 2014 at 14:01 UTC |