By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,373 Members | 1,984 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,373 IT Pros & Developers. It's quick & easy.

how to compare null string

100+
P: 236
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
Share this Question
Share on Google+
14 Replies


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

100+
P: 236
Hi all,

Any advise..?


Cheers...
Andrew
Dec 5 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
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
Expert 2.5K+
P: 4,059
see below...
Dec 5 '08 #5

KevinADC
Expert 2.5K+
P: 4,059
@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

100+
P: 236
ok. sorry...

can kindly assist Sirs?
Dec 5 '08 #7

KevinADC
Expert 2.5K+
P: 4,059
I already did, I advised you to use "ne" instead of "!=".
Dec 5 '08 #8

Ganon11
Expert 2.5K+
P: 3,652
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
Expert 2.5K+
P: 4,059
@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

100+
P: 236
Thanks Sirs... It worked... Cheers...
Dec 8 '08 #11

100+
P: 236
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
Expert 2.5K+
P: 4,059
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
Expert 2.5K+
P: 3,652
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

100+
P: 236
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.