[Bioperl-l] Filehandle issue
Chris Fields
cjfields at uiuc.edu
Tue Jan 16 18:04:00 UTC 2007
All,
I have noticed an interesting problem when running tests on a bioperl
bug (http://tinyurl.com/tamf8). Several Bio::AlignIO parsers, such
as Bio::AlignIO::phylip, return 0 instead of using 'return', which
causes problems when using newFh() for retrieving an IO::Handle:
----------------------------
$in = Bio::AlignIO->newFh(-fh => \*STDIN,
-format => 'phylip');
# $in is a GLOB
while( my $aln = <$in>)
{
print $aln->no_sequences(),"\n";
}
----------------------------
cjfields:~/tests/phylip cjfields$ more testaln.phylip | ./alignio.pl
4
Can't call method "no_sequences" without a package or object
reference at ./alignio.pl line 28, <STDIN> line 10.
The method call works for the first loop iteration, but the while
loop test evaluates '0' as true in this case. I think it's b/c perl
is treating the returned 0 like general text retrieved from a file
handle (the string '0') instead of EOF (with would return undef). I
ran a quick check on this and 'return 0' is used quite a bit in other
IO modules (though not all). Changing the 'return 0' to a simple
'return' fixes the problem.
How common is the above while loop idiom used when iterating through
data via a file handle?
chris
More information about the Bioperl-l
mailing list