in reply to UID 0 and getpwnam

You're confusing the concepts of "defined" versus "false", which are very different in Perl. The getpwnam document mentions

If the entry doesn't exist you get the undefined value.
Thus, you need a test as mirod has outlined above.

The same consideration applies anytime a value that represents falsehood in Perl (0 or the empty string) can be a legitimate return result from a function. One of my favorite Perl books, Effective Perl Programming has an excellent section on the difference.