http://www.perlmonks.org?node_id=442442

bradcathey has asked for the wisdom of the Perl Monks concerning the following question:

My application has a longish subroutine ('getinfo' in my example) that determines many values in one process. However, not all those values are used at once by the same calling routines, but only single values are used by various routines throughout the script.

I really don't want to duplicate the longish subroutine to just return the one value for a particular instance--I'd like to just have it written once and return all the values and then pick and choose the value I need once returned to the calling subroutine. But it seems inefficient and sloppy. Is there a better way? Here's a very simple example. Thanks.

sub routine_A { my ($name, $address) = getinfo(); print $name; } sub routine_B { my ($name, $address) = getinfo(); print $address; } sub getinfo { my $name = "Sam"; my $address = "123 Main St"; return ($name, $address); }


—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot