|more useful options|
Re^4: Use of wantarray Considered Harmful (bad use)by TGI (Parson)
|on Dec 15, 2008 at 08:03 UTC||Need Help??|
Oh yes it is! :)
Granted, if you create your @x by copying the large array you may wish to avoid copying, then it is pretty stupid to use wantarray to avoid making another copy.
But if you are working with an extant huge @x, its OK.
With only the one line we have to guess what the provenance of @x is.
Even if your read is destructive (like from a filehandle, or another similar iterator), there should be no problem. The ternary short circuits, and only one term is evaluated. So @x never gets evaluated in a list context and we have no massive destruction.
This assumes that you are working with a preexisting @x. If you are destructively copying from some source into @x, then the results will be ugly.
Anyhow, I think we basically agree that context sensitive return values can be useful to improve an API, but the should be used with care, and that they must be clearly documented. Also that creating an interface similar to readline (without creating massive unneeded copying of data) is a valid use of the technique.