I see someone has already told you about using the foreach instead of the
for loop like you are doing, But I don't see an answer to your question
about using split. Here is an untested snippet to give an example (This
assumes a tab delimiter between the first and second column, use the
delimiter you have in yours).:
open (ACCS, "C:\\Perl\\BioPerl-0.7\\Seqdata\\Accession.txt") or die "can't
open Accessions file";
@ets=<ACCS>;
foreach (@ets) {
($first, $second) = split(/\t/, $_); #(Splits current on a tab: \t)
# do what you need with the two variables
}
you are right, that is a very fast way to deal with files.
If you have regularly delimited files, and would prefer to work with them
using SQL like syntax, you might look at DBD::CSV for another alternative.
Steve Howard
-----Original Message-----
From: Stephen Henderson [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 12, 2001 9:59 AM
To: '[EMAIL PROTECTED]'
Subject: use of split command
I am trying to read a quite large file (ca 13000 lines) directly into an
array (for speed)
like this
open (ACCS, "C:\\Perl\\BioPerl-0.7\\Seqdata\\Accession.txt") or die "can't
open Accessions file";
@ets=<ACCS>;
$ets_count=@ets;
the actual data is a 2 column tab delimited file like:
<<...OLE_Obj...>>
etc....
I have been looking at the directions on using the split command in the
"Perl -in a nutshell book", but really can't figure out how to split the
@ets array into 2 separate arrays (say--@etsOrig + @etsRefSeq). I feel this
is probably simple but err...not to me.
Alternatively if you can tell me how to reference just the second part of
the line in a loop like e.g.
for($i=0; $i < $ets_count; $i++)
{
seq->some_function_of(the second column of @ets[$i}
}
maybe that would be quicker???