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

a conditional case

P: 6
Expand|Select|Wrap|Line Numbers
  1. $off = 'OFF'; chomp($off);  $on = 'ON'; chomp($on);    if(($fizrm == $off) && ($wizrm == $off))  {  system(' echo "Izmir RM Replication OFF" > /home/ahmet/repl_scr/izrmmail ');  }    elsif(($fizrm == $on) && ($wizrm == $on))  {  system(' echo "Izmir RM Replication ON" > /home/ahmet/repl_scr/izrmmail ');  }    elsif(($fizrm == $on) && ($wizrm == $off))  {  system(' echo "Izmir RM Replication PARTIAL" > /home/ahmet/repl_scr/izrmmail');  }    elsif(($fizrm == $off) && ($wizrm == $on))  {  system(' echo "Izmir RM Replication PARTIAL" > /home/ahmet/repl_scr/izrmmail');  }  
I have a conditional code like this, but always it selects the first output although the results must be second or third.

Is there something i miss?
Oct 6 '08 #1
Share this Question
Share on Google+
7 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Here is a tip, when posting code, it is a really good idea to make it readable. The code that you posted is all on one line and severely lacks readability. Next time, please make it a lot more legible.

Regards,

Jeff
Oct 6 '08 #2

numberwhun
Expert Mod 2.5K+
P: 3,503
Ok, so you are aware of what I was speaking about in my last post, here is how you should have presented your code:

Expand|Select|Wrap|Line Numbers
  1. $off = 'OFF'; 
  2. chomp($off);  
  3.  
  4. $on = 'ON'; 
  5. chomp($on);
  6.  
  7. if(($fizrm == $off) && ($wizrm == $off))  { 
  8.     system(' echo "Izmir RM Replication OFF" > /home/ahmet/repl_scr/izrmmail '); 
  9. }
  10. elsif(($fizrm == $on) && ($wizrm == $on))  {
  11.     system(' echo "Izmir RM Replication ON" > /home/ahmet/repl_scr/izrmmail ');
  12. }    elsif(($fizrm == $on) && ($wizrm == $off)) {
  13.     system(' echo "Izmir RM Replication PARTIAL" > /home/ahmet/repl_scr/izrmmail');
  14. }
  15. elsif(($fizrm == $off) && ($wizrm == $on)) {
  16.     system(' echo "Izmir RM Replication PARTIAL" > /home/ahmet/repl_scr/izrmmail');
  17.  
Now, in looking at this, I notice you are using a numerical comparison operator (==) to compare text, when you shoudl be using "eq" instead. "eq" will compare text.

Make sure that you have the following pragmas in use:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
We have no way of knowing as we cannot see your entire script. If you did have them on, you should have gotten warnings about doing a numerical comparison on a string.

Also, just a note. You shouldn't have to "chomp" the variables as you are setting them in the script and not getting the input from command line. The "chomp" command would remove the carriage return that the user enters after typing their entry.


Regards,

Jeff
Oct 6 '08 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
Ok, I have deleted your new post as it is a duplicate. Please do not post duplicate thread.

Regards,

Jeff
Oct 6 '08 #4

P: 6
It's OK now, thanks so much, also sorry for duplicate post.
Oct 6 '08 #5

eWish
Expert 100+
P: 971
So, did you figured out your problem?

--Kevin
Oct 6 '08 #6

numberwhun
Expert Mod 2.5K+
P: 3,503
So, did you figured out your problem?

--Kevin
I think he was using the wrong comparison operator as I had suggested to him, but can only assume as he didn't say.

Regards,

Jeff
Oct 7 '08 #7

KevinADC
Expert 2.5K+
P: 4,059
Yea, if he uses == to compare strings this:

if(($fizrm == $off) && ($wizrm == $off))

will evaluate to:

if((0 == 0) && (0 == 0))

which will obviously evaluate to true and cause a problem.
Oct 7 '08 #8

Post your reply

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