> -----Original Message----- > From: Fei Li [mailto:[EMAIL PROTECTED] > Sent: Tuesday, May 31, 2005 6:59 PM > To: Chris Heiland > Cc: beginners@perl.org > Subject: Re: please help me to check why this perl script > does not work! > > Hi, Chris, > > Thanks for your code. I have test in my computer and it works with > necessary modification to suit for my case. > > Can you give me some brief ideas that why this code is much > faster than previous one. thanks much! > > --Frank > > On 5/31/05, Chris Heiland <[EMAIL PROTECTED]> wrote: [snip] > > > > > > > > > -- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] For > > > additional commands, e-mail: [EMAIL PROTECTED] > > > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > > > > > > Assuming that was the case, here is what should be a much faster > > version of the same code. > > > > UNTESTED: > > > > #!/usr/bin/perl > > > > use warnings; > > use strict; > > > > use HTTP::Request::Common; > > use LWP::UserAgent; > > > > my $browser = LWP::UserAgent->new; > > > > my $infile = "my_test_file"; #input my Fasta file > > > > open( INPUT, "$infile" ) or die "can not open $infile: $!"; We just need the total number of lines right now, nothing else stored > my $total > > = <INPUT>; open( OUTPUT, ">>$infile.ChloroP.res" ) or die "Cannot > > create the output > > file: $!"; > > Mostly the different is we are attacking the file one line at a time. Before everything was loaded in a variable then gone through. Much faster not to load the entire file into memory first. Here is the for every line in the file part: > > while (<INPUT>) { Let's kill off any return characters > > chomp; Take advantage of the "$_" Special variable representing a line in the file > > my $response = > > $browser->post('http://www.cbs.dtu.dk/cgi-bin/nph-webface', > > [ "seqpaste" => "$_", "submit" => "Submit"] > > ); > > Could warn first but we assume most cases will not fail, test to see if They succeed first, then worry if they fail > > if ($response->is_success) { > > print OUTPUT "$response->content\n"; > > print OUTPUT > "\n*********************************\n\n\n"; > > } else { > > warn "WARN!: ", $response->status_line, "\n"; > > } > > $. Prints the current line number of the file handle opened No need to use a counter in this case Also the total is gathered before > > print "$. of $total finished\n"; } > > > > close OUTPUT; > > close INPUT; > > > > Chris > > > > -- [snip] > Sure, see comments above.
Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>