That's the semi-predicate problem. If a function is supposed to return a string, which may be empty without this being an error, and may also have to return failure, one way to make the distinction is to return a reference to the string rather than the string itself (a reference will always be true even is the string is empty) and undef when the function fails.
I had to do something similar recently where a function had to return an array (and returning an empty array was not supposed to be an error). I just decided to return a reference to the array or undef when the input was exhausted (failure). This way I could distinguish between the three different cases and act accordingly
In reply to Re^2: Croak, return et al.
by Laurent_R
in thread Croak, return et al.
by packetstormer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |