[Bioperl-l] Bio::Cluster

Andrew Macgregor andrew@anatomy.otago.ac.nz
Wed, 07 Aug 2002 09:08:37 +1200


Hilmar Lapp wrote:

>is there a 
> reason you don't want to return undef for a slot that's undef?
> 
Hi Hilmar,

No there's not really a reason I do this. When I was putting this together I
based it on Seq.pm. So I looked at code like this:

sub primary_id {
   my ($obj,$value) = @_;

   if( defined $value) {
      $obj->{'primary_id'} = $value;
    }
   if( ! exists $obj->{'primary_id'} ) {
       return "$obj";
   }
   return $obj->{'primary_id'};
}


And basically followed that pattern. When something isn't present I return
the stringified reference. I thought I might be breaking something in the
bigger picture if I did not.

I guess looking at this more closely this is only used for primary_id. What
purpose exactly does ' return "$obj" ' serve here? I guess my code should
just be something like:

sub gene {
   my ($obj,$value) = @_;

   if( defined $value) {
      $obj->{'gene'} = $value;
    }
   return $obj->{'gene'};
}


Which cuts out:

   if( ! exists $obj->{'gene'} ) {
       return "$obj";
   }


Does that sound right?

Cheers, Andrew.