in reply to Re^2: reading and working with grow.out files
in thread reading and working with grow.out files
Hi, take a look at this code:
The program will match each ligand code to the given file and print out the lines where there is a match
Good luck with your research
Mr Guy
It assumes that the list of text files and ligand codes are in a tab delimited file called input_file.txt. It will look like thisuse strict; use warnings; use Carp qw(croak); { my $input_file = "input_file.txt"; my @lines = slurp($input_file); for my $line (@lines){ my ($filename, $ligand) = split(/\t/, $line); open(FILE, '<', $filename) or die "Cannot open file: $!"; while (my $line = <FILE>) { print $line if $line =~ /$ligand/; } close(FILE); } } ##Slurps a file into a list sub slurp { my ($file) = @_; my (@data, @data_chomped); open IN, "<", $file or croak "can't open $file\n"; @data = <IN>; for my $line (@data){ chomp($line); push (@data_chomped, $line); } close IN; return (@data_chomped); }
You can also delimit it by ',' or any other delimiter, but you will have to update the split functionfile1.txt MC9 file2.txt ASH
The program will match each ligand code to the given file and print out the lines where there is a match
Good luck with your research
Mr Guy
|
---|
In Section
Seekers of Perl Wisdom