inlining a method return

nkuipers nkuipers at uvic.ca
Wed Nov 20 20:07:31 CST 2002


[This is being redirected by Peter since it bounced because it matches 
/^sub\b/m, which is an administrative request.  I've changed the lidst 
options to ignore things like this from now on.  This should look to 
you like it came from Nathanael.]

At least, I think inlining is the appropriate term.

Here's the situation.  I have a sequence object which has a get/set method for
most of its properties.  For example:

sub seq {
         my $caller = shift;
	die "No object.\n" unless ref $caller;
         @_ ? $caller->{SEQUENCE} = $_[0] : $caller->{SEQUENCE};
}

This allows something like

print "This is the sequence: ",$obj->seq,"\n";

Moreover, $obj->seq can be inlined with something like length, as in my len
method:

sub len {
	my $caller = shift;
	die "No object.\n" unless ref $caller;
	$caller->bare;
	length( $caller->seq );
}

Finally, I can use msy/// on the sequence key directly, as in:

sub bare {
	my $caller = shift;
	die "No object.\n" unless ref $caller;
	$caller->{SEQUENCE} =~ s/[^rndeqhilkmfpswyvacgtux*-]//gi;
}

However, I cannot say something like this:

sub residues {
	my $caller = shift;
	die "No object.\n" unless ref $caller;
	my %args = ( GC => '', @_ );
	$caller->bare;
	$caller->uppercase;
	my $p = $caller->profile;
	#begin problem line
	$p->{$1}++ while $caller->seq =~ m/([ARNDCQEGHILKMFPSTWYVU])/g;
	#end problem line
	if ( $args{GC} ) {
		die "%GC on a protein.\n"
		unless ( $caller->is_dna || $caller->is_rna );
		no warnings;
		my $gc = ( $p->{G} + $p->{C} ) / $caller->len * 100;
	}
}

How would I inline a get/set method so that I could use it in a msy///
statement directly rather than first setting a $tmp variable and using the
$tmp (which is my current workaround)?

Many thanks,

Nathanael




More information about the Victoria-pm mailing list