Don't ask to ask, just ask | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I think that use of wantarray() to modify return behavior should be generally avoided. In my opinion it is a clear violation of the principal of least surprise.
As an example, consider this real-world case from Bricolage:
That works fine, but this doesn't:
That's because Bricolage list() methods (and lots of other Bricolage methods) try to be helpful and return array refs in scalar context. I've personally found a number of bugs that turned out to be caused by this problem, and I'm sure there are more waiting to be found. There may be cases where wantarray() is useful, but I definitely don't consider it a general-purpose tool. -sam In reply to Re: What should be returned in scalar context?
by samtregar
|
|