Performance of chained methods.

Scott Penrose scottp at
Tue Oct 29 21:48:12 CST 2002

Hey Dudes.

I have a bit of code that looks like this

	my $ref =  

Perfectly legitimate in that we are effectively getting a grass root  
element and drilling down.

My problem is that each of these can fail. In my particular case I  
don't care which fail or why, is it ok therefore to do this

	my $ref = eval  
	return undef if ($@);

Or is that a really bad practice?, is there a better way ?, otherwise I  
have to fall down to the usual practice of one at a time.

	my $obj1 = SomeClass->FirstMethod($param1)				or return undef;
	my $obj2 = $obj1->AnotherMethod($param2)
		or return undef;
	my $ref = $obj2->MoreMethods()
		or return undef;


Scott Penrose
Welcome to the Digital Dimension
scottp at

Dismaimer: Contents of this mail and signature are bound to change  
randomly. Whilst every attempt has been made to control said  
randomness, the author wishes to remain blameless for the number of  
eggs that damn chicken laid. Oh and I don't want to hear about  
butterflies either.

More information about the Melbourne-pm mailing list