Need help with perl script to read in values from a files
Hi all,
I'm trying to write a script to query a database with the scientific names of organisms for their taxonomic IDs to automatically bin DNA sequences in a dataset as being from an animal, bacteria, etc. I have a text file containing many scientific names that I would like to run through this script. I'm having a hard time editing the script to iterate through the text file pulling in variables one after the other and none of the examples I've been able to find on the web match the situation I'm in. I realize that I'll need to change the lines "my @scientific_name = ("Neosartorya fischeri NRRL 181");" and "foreach my $scientific_name (@scientific_name) {" but otherwise I'm really stuck. Here's the script I'm trying to edit: Code:
use strict; Code:
Caldicellulosiruptor owensensis OL Kevin |
I'm not entirely clear, but if you are asking about how to read file line by line
Code:
open(KFILE, "<", "kfile.txt" ) or die "Can't open kfile: $!\n"; Also, I'd avoid having scalars and arrays having effectively the same name, even if they are in separate name-spaces; it becomes prone to difficult to find typos as the code gets longer. To get separate "fields" from your recs (if you need to), use http://perldoc.perl.org/functions/split.html HTH - come back if you need more :) |
Thanks for the help. I'm a novice with perl but between that and some more web searching, I got something that works figured out:
Code:
use strict; |
Please use the proper Perl way of reading files as per my example.
I'd also point out that it splits on new lines by default (you can change that for funky files). I also re-iterate my advice about not using the 'same' names for scalars/arrays (& indeed hashes). You'll thank me later... |
|
All times are GMT -5. The time now is 10:05 PM. |