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


in reply to Hope a subroutine will return undef by default

What if instead of trying to bend Perl to be like ... well ... what language are you actually trying to mimic here? ... what if instead you just got used to Perl being Perl? I can understand a code policy requiring an explicit return statement ensured either by code review or (if such thing is possible) using Perl::Critic, but no matter what way you do it this is only ever gonna cause confusion and pain. I'm pretty sure you could do something using source code filters or somesuch hackery, but you really do not want to do that!

Jenda
Enoch was right!
Enjoy the last years of Rome.

  • Comment on Re: Hope a subroutine will return undef by default

Replies are listed 'Best First'.
Re^2: Hope a subroutine will return undef by default
by LanX (Saint) on Feb 12, 2014 at 01:00 UTC
    > what language are you actually trying to mimic here?

    At least Javascript comes to mind (update: and Python)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      You are right, javascript does this. "return ;" in the middle of a function has the same return value as the case when execution of the function goes the end of the function body without a return statement --- both cases return "undefined" or null. No surprises.