terriblue has asked for the wisdom of the Perl Monks concerning the following question:

The method "query_name" will not run because $result is undefined when I use Dumper. I thought I accounted for this in my first "if" statement where if "0" is returned, then it's supposed to wait 5 seconds and check the server again for a result. I can't seem to figure out exactly where the problem is. Here is the script:
#loop over rids to check server for a result foreach my $rid (@rids) { my $blast_results = $blast_factory -> retrieve_blast($rid) +; if ($blast_results == 0) { #still waiting to complete sear +ch print STDERR "."; #watch dots while waiting sleep 5; #pause between checking for results } elsif ($blast_results == (-1)) {#error returned, remove RI +D from stack print STDERR "retrieve_blast returns -1\n"; $blast_factory -> remove_rid($rid); } #use Bio::SearchIO to return a Bio::SearchIO result object else { print "Receiving blast results...\n"; my $result = $blast_results -> next_result(); print Dumper ($result); my $filename = $result -> query_name()."\.out"; $blast_factory -> save_output ($filename); $blast_factory -> remove_rid($rid);
Can anyone see the problem?

Replies are listed 'Best First'.
Re: undefined value returned
by japhy (Canon) on Jul 19, 2005 at 18:47 UTC
    Well, I don't know how the next_result() method works, but it's not the same as the retrieve_blast() method, I would guess. A true value from retrieve_blast() doesn't necessarily mean there's a true value from next_result(), it seems.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re: undefined value returned
by socketdave (Curate) on Jul 19, 2005 at 20:47 UTC
    0 and undef are not the same thing... do an

    if (! defined $blast_results)
Re: undefined value returned
by mifflin (Curate) on Jul 19, 2005 at 18:48 UTC
    Looks like your tests are on $blast_results, not $results. Is $blast_results a valid object that can call a method called next_result? How does next_result indicate that there are no more results? Is it possible that it would return undef for this condition?