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); }
In reply to More efficient return of values from sub by bradcathey
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |