in reply to Re^12: "advanced" Perl functions and maintainability
in thread "advanced" Perl functions and maintainability
The last expression executed in a subroutine will be the value returned from that subroutine. Always. Without exception.
Moreover, Perl is not the only language that supports that particular idiom. Both Scheme and ML do as well if my memory serves me correctly. It makes somewhat more sense in those languages where a "block" is just a sequence of expressions and there's no real notion of a "statement." OTOH, it's consistent with the behavior of do and eval in block syntax (not to mention map and grep, though some posters in this thread seem opposed to this usage), where it is required because those BLOCKs are not subroutines.
|
|---|