Re: Subroutine return value

2025-05-14 Thread Jim Gibson via beginners
Put this line as the last line executed in your subroutine: return $sum; That makes it explicit as to what you want the subroutine to do. Don’t depend upon some obscure behavior of Perl to save a few keystrokes. Your program will be better for it. > On May 14, 2025, at 4:15 PM, Daryl

Subroutine return value

2025-05-14 Thread Daryl Lee
In “Learning Perl”, Pg. 116, is found this sentence: Whatever calculation is last performed in a subroutine is automatically also the return value. I have a subroutine that (almost) ends with this loop: foreach my $line (@lines) { $sum += evaluate($line); } What I want to return i