in reply to Re: Best practices for warnings about wrong context
in thread Best practices for warnings about wrong context

Maybe I've taken references to a few different subs and passed them around, and then at some point call whichever one has been passed? Maybe some other sub returns a scalar, a hashref, a list, or whatever. What happens if I want to use the sub that refuses to be used in list context or scalar context?

Well I can wrap it in another sub, maybe an anonymous sub, which doesn't seem like a heart-rending, mind-warping workaround. Should wrapping it be necessary? Who's to say, really? If someone wants to return any kind of user data or status information, it would require the wrapper anyway since the author didn't return anything from the original sub. One might as well have the wrapper call it in void context then return whatever you like.

  • Comment on Re^2: Best practices for warnings about wrong context