how to compare null string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • happyse27
    New Member
    • Sep 2008
    • 236

    how to compare null string

    Hi all,

    I did the null string comparison for below...

    But could not work as i keyed some value into the $company field but it did not print out okok, but not ok. I used if ($company != '') also did not help...

    Can you kindly advise?


    Cheers...
    Andrew

    Code:
    if ($company != "" )
    {
    
      print "okok \n";
    }
    else
    {
    
      print "Not ok \n";
    }
  • happyse27
    New Member
    • Sep 2008
    • 236

    #2
    how to compare null string

    Hi all,

    I used eq as it is string.. but still didnt work..

    Cheers...
    Andrew

    Code:
    if ($company eq "" )
    {
    
      print "okok \n";
    }
    else
    {
    
      print "Not ok \n";
    }

    Comment

    • happyse27
      New Member
      • Sep 2008
      • 236

      #3
      Hi all,

      Any advise..?


      Cheers...
      Andrew

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Use "ne" instead of "!=". There are string operators and math operators, use the correct ones depending on what you are trying to compare.

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          see below...

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            Originally posted by happyse27
            Hi all,

            Any advise..?


            Cheers...
            Andrew
            Andrew, this is not tech support. You're asking after 5 minutes if anyone can advise after posting your last question. You need to be more patient than that.

            Comment

            • happyse27
              New Member
              • Sep 2008
              • 236

              #7
              ok. sorry...

              can kindly assist Sirs?

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                I already did, I advised you to use "ne" instead of "!=".

                Comment

                • Ganon11
                  Recognized Expert Specialist
                  • Oct 2006
                  • 3651

                  #9
                  You can also simply use $company, since the null string is a FALSE value:

                  Code:
                  if ($company) {
                     print "It's not null.\n";
                  } else {
                     print "It's null.\n";
                  }

                  Comment

                  • KevinADC
                    Recognized Expert Specialist
                    • Jan 2007
                    • 4092

                    #10
                    Originally posted by Ganon11
                    You can also simply use $company, since the null string is a FALSE value:

                    Code:
                    if ($company) {
                       print "It's not null.\n";
                    } else {
                       print "It's null.\n";
                    }
                    Good observation. But thats also true if $company is equal to 0 which perl considers a false value:

                    $company = 0;

                    something for the unwary to keep in mind.

                    Comment

                    • happyse27
                      New Member
                      • Sep 2008
                      • 236

                      #11
                      Thanks Sirs... It worked... Cheers...

                      Comment

                      • happyse27
                        New Member
                        • Sep 2008
                        • 236

                        #12
                        Hi Moderator,

                        Why I am not allow to post new thread? What rules did I violate? And I wasnt intentional... Not even a chance can be given?

                        Regards,
                        Andrew

                        Comment

                        • KevinADC
                          Recognized Expert Specialist
                          • Jan 2007
                          • 4092

                          #13
                          This website has been undergoing a lot of changes lately and if you can't post a new thread is probably something to do with the changes. Try again.

                          Comment

                          • Ganon11
                            Recognized Expert Specialist
                            • Oct 2006
                            • 3651

                            #14
                            happyse27,

                            Just to reiterate what KevinADC said, I don't think you've done anything to warrant any sort of 'posting ban'. It was likely an error due to our changing interface. Please try again.

                            Comment

                            • happyse27
                              New Member
                              • Sep 2008
                              • 236

                              #15
                              how to get the user registration country and provinces modules

                              Thanks Again. Sirs.. Appreciated...
                              Really needed help...

                              Btw, how to get above country / province modules, it is to register username and passwords and also the country, the state(province) for the people who serve, country::locale seemed to be incomplete.


                              Cheers...
                              Andrew

                              Comment

                              Working...