I'd like to make a few adjustments on this code, and give you some things you might 
want
to concider using:

open (ACCS, "C:\\Perl\\BioPerl-0.7\\Seqdata\\Accession.txt") or die "can't open 
Accessions
file ", $!;
# this will produce also the error returned by the system call... usefull for figuring 
out
*why* the file wasnt opened
# you might want to concider putting the location in a var name, like $loc and have 
open
operate on $loc... makes it easy if you use that file more often in the script.

# depending on size of the file, you will probably want to do one of the following:

#this will read the entire file into a string and will save you somewhere around 24 
bytes
per line compared to an array
#quick math says that saves you ~2.4mb of ram on 100k lines
#putting it in a string is nice for doing s///, m// operations and passing it around to
subroutines etc
*** Option 1 ***
my $in;
{local $/; $in = <HANDLE> }
while(split "\n", $in) {
    my ($one, $two) = split "\t";        #assuming a tabdelimited list again
    # do something with those vars
}

#however, you might just want to lower memory load and use:
*** Option 2 ***
while (<HANDLE>) {
    my ($one, $two) = split "\t";        #assuming a tabdelimited list again
    # do something with those vars
}

doing as mentioned below is not very smart, seeing it first copies all the info to an
array, and then handles it one line at a time anyway in the for loop
this has the memory load of option 1, while it has the functionality of option 2... the
worst of both worlds so to speak

last remark i want to make is that it's always good to run 'use strict' and force 
yourself
to use lexicals (my'd vars).

hope this helps,

Jos Boumans

> 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.
>

Reply via email to