in reply to Re: unix to perl questions
in thread unix to perl questions

I feel like am stalking you...lol Really I am fascinated by the code. Getchoice would be function or subroutine? This eliminates the Do-While loop.I've also never seen "defined" what does that do exactly is it another way of doing a comparison?

Replies are listed 'Best First'.
Re^3: unix to perl questions
by dsheroh (Monsignor) on Mar 12, 2015 at 15:49 UTC
    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.

      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.
      Is "undefined" similar to null in Perl? I have yet to see null in Perl.
        Yes. See undef.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ