in reply to Re: Returning undef: The point I would like Damian to reconsider
in thread Returning undef: The point I would like Damian to reconsider
Don't change subroutine results based on list or scalar context.
Coercing a strictly list returning function into returning a scalar would be wrong and could be treated as an error of the caller if detected.
If I were trying to follow that advice, what should I do if a subroutine that returns a list in a list context gets called instead in a scalar or void context? "die"?
But you caught me there, the subroutine would still need to be context-aware to detect that situation.
The impact on the subroutine code could be kept at bay, though, if we tucked that piece of logic away, say, in a listonly convenience function.
Is something like that already on CPAN?