469,266 Members | 1,768 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,266 developers. It's quick & easy.

how to compare null string

236 100+
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

Expand|Select|Wrap|Line Numbers
  1. if ($company != "" )
  2. {
  3.  
  4.   print "okok \n";
  5. }
  6. else
  7. {
  8.  
  9.   print "Not ok \n";
  10. }
  11.  
Dec 5 '08 #1
14 14304
happyse27
236 100+
Hi all,

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

Cheers...
Andrew

Expand|Select|Wrap|Line Numbers
  1. if ($company eq "" )
  2. {
  3.  
  4.   print "okok \n";
  5. }
  6. else
  7. {
  8.  
  9.   print "Not ok \n";
  10. }
  11.  
Dec 5 '08 #2
happyse27
236 100+
Hi all,

Any advise..?


Cheers...
Andrew
Dec 5 '08 #3
KevinADC
4,059 Expert 2GB
Use "ne" instead of "!=". There are string operators and math operators, use the correct ones depending on what you are trying to compare.
Dec 5 '08 #4
KevinADC
4,059 Expert 2GB
see below...
Dec 5 '08 #5
KevinADC
4,059 Expert 2GB
@happyse27
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.
Dec 5 '08 #6
happyse27
236 100+
ok. sorry...

can kindly assist Sirs?
Dec 5 '08 #7
KevinADC
4,059 Expert 2GB
I already did, I advised you to use "ne" instead of "!=".
Dec 5 '08 #8
Ganon11
3,652 Expert 2GB
You can also simply use $company, since the null string is a FALSE value:

Expand|Select|Wrap|Line Numbers
  1. if ($company) {
  2.    print "It's not null.\n";
  3. } else {
  4.    print "It's null.\n";
  5. }
Dec 6 '08 #9
KevinADC
4,059 Expert 2GB
@Ganon11
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.
Dec 6 '08 #10
happyse27
236 100+
Thanks Sirs... It worked... Cheers...
Dec 8 '08 #11
happyse27
236 100+
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
Dec 8 '08 #12
KevinADC
4,059 Expert 2GB
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.
Dec 8 '08 #13
Ganon11
3,652 Expert 2GB
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.
Dec 9 '08 #14
happyse27
236 100+
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
Dec 9 '08 #15

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by DiggidyMack69 | last post: by
1 post views Thread by Laurent Liegeois | last post: by
5 posts views Thread by John Smith | last post: by
2 posts views Thread by bill | last post: by
10 posts views Thread by lovecreatesbea... | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.