in reply to Re^2: What to test in a new module
in thread What to test in a new module

It's safer to explicitly return as otherwise the value of the last expression is returned.

He did say "unless you intentionally are returning undef". I agree with stevieb on that point; however, in my code if I am intentionally returning undef I make that explicit with return(); I never use return; in my code unless I am returning early from a sub which is not expected to return a value. (If the caller insists on doing something with the returned value from such a sub, TNMP.)

Replies are listed 'Best First'.
Re^4: What to test in a new module
by swl (Prior) on Jul 08, 2023 at 05:56 UTC

    Thanks for the clarification. Two other points, which you are probably well aware of but some readers might not be:

    return; and return(); are the same, although the brackets do make it more visually distinct and perhaps that's your point.

    return; in list context returns the empty list. This means it is effectively the same as return wantarray ? () : undef; unless it is called in void context. Your use of it when not expecting a return value implies void context, though, so perhaps this point is moot.

      the brackets do make it more visually distinct and perhaps that's your point.

      That is precisely my point.

      It isn't obvious that return; returns undef, so I don't depend on that. That is, I don't use that construction when that's what I want to do.

        > It isn't obvious that return; returns undef

        It doesn't. It returns undef in a scalar context, but an empty list in a list context.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]