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

Fields, Christopher J cjfields at illinois.edu
Wed Jan 29 03:14:20 UTC 2014


We learn from past mistakes.  I have no problem in following a best practices approach, namely avoiding modification of $_.   So, feel free to squash these (with prejudice) as long as they pass tests.

chris

PS - The modification of Bio::Root::IO::_readline would be a good place to start :)

On Jan 28, 2014, at 2: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.
> 
> Cheers,
> 
> Francisco J. Ossandon
> 
> -----Mensaje original-----
> De: bioperl-l-bounces at lists.open-bio.org
> [mailto:bioperl-l-bounces at lists.open-bio.org] En nombre de Carnë Draug
> Enviado el: martes, 28 de enero de 2014 15:00
> Para: <bioperl-l at bioperl.org>
> Asunto: [Bioperl-l] Bio::SeqIO modifies $_
> 
> Hi
> 
> I was under the impression that we had changed to use the builtin bug
> tracker of github but for some reason, I can't do it, so I'm reporting it
> here.
> 
> Consider the following very simple example:
> 
> use Bio::SeqIO;
> my @files = ("NP_001136062.gb", "NP_001137300.gb"); my @seqs = map
> {Bio::SeqIO->new(-file => $_)->next_seq;} @files;
> 
> or the more canonical
> 
> foreach (@files) {
>  my $seq = Bio::SeqIO->new(-file => $_)->next_seq; }
> 
> This very simple snippet modifies @files. Following this, each element of
> @lines becomes the string "//\n"
> 
> Stepping through the code with the debugger (and a lot of help from the
> people at #perl), one finds that this is because there's an assignment to $_
> in many places of BioPerl. The first one is in Bio::SeqIO::_guess_format
> [1]. Fixing it in this place is very easy but I soon found out that this
> happens in multiple places. From the example above, the debugger finds that
> this happens multiple times in:
> 
> Bio::Root::IO::_readline
> Bio::SeqIO::genbank::_read_GenBank_References
> Bio::SeqIO::genbank::next_seq
> Bio::SeqIO::genbank::_read_FTHelper_GenBank
> 
> Note that simply doing "my $_" will not work in all places [2] and is not
> recommended [3].
> 
> Carnë
> 
> [1]
> https://github.com/bioperl/bioperl-live/blob/ee6a77761340db12c747ab8cde387e9
> 58e5f8a0f/Bio/SeqIO.pm#L680
> [2]
> https://github.com/bioperl/bioperl-live/blob/ee6a77761340db12c747ab8cde387e9
> 58e5f8a0f/Bio/SeqIO/genbank.pm#L838
> [3]
> http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Lexical_$__is_now_
> experimental
> 
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
> 
> 
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l





More information about the Bioperl-l mailing list