in reply to A question about method return values and error checking

This is definitely subjective, and a point for documentation. In both cases, $os->name is trying to communicate that the $os object has no name. It's actually more consistent with this interpretation in my mind to return an undef here, since an undef feels more like a null to me, as opposed to an empty string. But either is acceptable so long as it's documented that way.

Assuming you are dealing with 5.10.0 or later (I think), the Logical Defined Or actually gives a very elegant way of writing your case, and makes undef a preferred choice:

printf "Operating System: %s\n", $os->name( long => 1 ) // 'undef';
or even
printf "Operating System: %s\n", $os->name( long => 1 ) // (`uname -o +-r` =~ s/\n//r);

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: A question about method return values and error checking
by wee (Scribe) on Nov 04, 2015 at 21:56 UTC
    I've been thinking about it and I am leaning toward this. We had no idea that it might even return undef. What operating system has no name? And with the docs like they were, it's just not something we accounted for. But the logical defined or looks like the way to go.
      If you wanted to be particularly crazy, you could even go with:
      printf "Operating System: %s\n", $os->name( long => 1 ) // (`uname -o -r` =~ s/\n//r) || 'undefined';

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.