[Bioperl-l] get_nof_contigs returns undef

Heikki Lehvaslaiho heikki.lehvaslaiho at gmail.com
Mon Oct 3 07:34:56 EDT 2005


It is in now. I thought that you had access to the CVS and had done it 
already. Sorry,
  -Heikki

On Monday 03 October 2005 00:21, Wes Barris wrote:
> Heikki Lehvaslaiho wrote:
> > Ah, thanks, the extra square brackets do the trick!
> >
> > return scalar( @{[moose()]} );
> >
> > sub get_nof_contigs {
> >       my $self = shift;
> >       return scalar( @{[$self->get_contig_ids()]} );
> > }
> >
> > Talk about clean syntax! ;-)
>
> Yes, one might get a headache trying to figure out what that line is
> doing.
>
> I notice that this fix has not made it into the code yet.  Should I
> submit a bug report to get this fix pushed through?
>
> > Seriously, I do agree with you that it is better to be wordy and clear
> > than terse and hard to read.
> >
> >  -Heikki
> >
> > On Sunday 25 September 2005 19:42, George Hartzell wrote:
> >>Heikki Lehvaslaiho writes:
> >> > So the question is how to force list context for a subroutine. This is
> >> > something I've often wondered and have not found a clean solution.
> >> > [...]
> >>
> >>No, [I think] that's not the problem here.
> >>
> >>The problem is that there's a call to sort() buried in the
> >>get_nof_contigs return statement and sort is a Surprising function (it
> >>returns undef when called in a scalar context).
> >>
> >><windmill-tilting>
> >>The cleanest fix would be to petition the Perl community to change the
> >>semantics of the sort() function so that it's not so Surprising.... ;)
> >></windmill-tilting>
> >>
> >>In the meantime, I tend to avoid doing real work in a return
> >>statement, I'd do the work w/in the body of the function, assign the
> >>results to an array (e.g. @results), then return that.
> >>
> >>It looks a bit wordy and people think I'm paranoid, but it's just so
> >>much easier for me to be safe than to try to remember whether Perl's
> >>going to Do The Right Thing or just bite me in the ass....
> >>
> >>If you really want to force something into a list context, the second
> >>paragraph of the documentation for scalar() says this:
> >>
> >>   There is no equivalent operator to force an expression to be
> >>   interpolated in list context because in practice, this is never
> >>   needed.  If you really wanted to do so, however, you could use
> >>   the construction "@{[ (some expression) ]}", but usually a sim-
> >>   ple "(some expression)" suffices.
> >>
> >>
> >>g
> >>
> >>_______________________________________________
> >>Bioperl-l mailing list
> >>Bioperl-l at portal.open-bio.org
> >>http://portal.open-bio.org/mailman/listinfo/bioperl-l

-- 
______ _/      _/_____________________________________________________
      _/      _/                      http://www.ebi.ac.uk/mutations/
     _/  _/  _/  Heikki Lehvaslaiho    heikki at_ebi _ac _uk
    _/_/_/_/_/  EMBL Outstation, European Bioinformatics Institute
   _/  _/  _/  Wellcome Trust Genome Campus, Hinxton
  _/  _/  _/  Cambridge, CB10 1SD, United Kingdom
     _/      Phone: +44 (0)1223 494 644   FAX: +44 (0)1223 494 468
___ _/_/_/_/_/________________________________________________________


More information about the Bioperl-l mailing list