[Bioperl-l] How to print get_available_databases?

Dave Messina David.Messina at sbc.su.se
Fri Jun 4 11:39:44 EDT 2010

Hi Peng,

In your code

> foreach($factory->get_available_databases) {
>  print
>  print "\n";
> }

You're not printing anything that's coming from get_available_databases.

You say

print print

Which means print the return value from the print command, which is true, or in other words, '1'.

Not what you want.

Here you have encountered the peril of implicit variables.

When you write a foreach loop, the idea is to put a name on each item, one after the other, from an array of items. So it's good idea to be explicit about what that name is.

For example:

foreach my $database ($factory->get_available_databases) {
	print $database, "\n";

In this way it's much clearer what you are doing (and it actually works! :) ).


More information about the Bioperl-l mailing list