[Bioperl-l] Bio::SeqIO modifies $_

Leon Timmermans l.m.timmermans at students.uu.nl
Sun Feb 2 23:06:46 UTC 2014


On Tue, Jan 28, 2014 at 9:21 PM, Francisco J. Ossandón <
fossandonc at hotmail.com> wrote:

> Hi,
> One of things that have always bugged me a little about Bioperl code is
> that
> it extensively use "$_", when parsing blast for example:
> * "while ( defined( $_ = $self->_readline ) ) {", instead of "while (
> defined( my $line = $self->_readline ) ) {"
> * elsif(/^Reference:\s+(.*)$/) {
> * etc.
>
> For now I have been following the current style of keeping $_ when making
> fixes, but in my own scripts I always create named scalars which also
> avoids
> confusion ("foreach my $element ()", "while (my $bar =)", etc.).
>
> I would vote for extensive removal of $_ use, except in cases where really
> needed (maybe longer code, but also more clarity), but I will not have the
> free time needed to do it for several weeks.
>

$_ is not necessarily a bad idea as long as it is localized properly;
either by «local $_ = ...» or «for (...) {...}». But I agree most of the
time it should be avoided.

Leon




More information about the Bioperl-l mailing list