defined does pretty much exactly what the English word suggests: It tests whether the variable has a defined value, which is to say, whether any value has ever been assigned to the variable.
In this particular case, if(defined getpwnam($nUsername)) checks to see whether getpwnam returns a value at all:
- If it finds the user, it will return something and "something" is always defined, so the test evaluates as true.
- If it doesn't find the user, it will return nothing (not just an empty value or a false value, but the absence of a value - in Perl, this not-a-value is called undef, for "undefined"), and the test evaluates as false. | [reply] [d/l] [select] |
Just to add to that: The case where the function returns a "defined but false" value is the user "root", who has a UID of 0.
| [reply] |
Is "undefined" similar to null in Perl? I have yet to see null in Perl.
| [reply] |
| [reply] |