in reply to Functions that return nothing, nada, failure...
My opinion on this subject hasn't really changed in past 1.5 years.
Returning an empty list may seem like the "safe" thing to do on error (because undef in list context is a single element list which might be construed as "success") but it's jsut as prone to confusion as returning an empty list, which might get flattened into another list and cause other problems latter on. At least with an undef, people with warnings on will get a "Use of uninitialized value..." as soon as they try to use the results from your function.
But in the end, it really doesn't matter which approach you take, as long as you document the behavior extensively, and make it the callers responsibility to force the calling context as needed to get a result that makes sense to them.
|
|---|