467,109 Members | 1,357 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

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

a conditional case

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
  • viewed: 1337
Share:
7 Replies
numberwhun
Expert Mod 2GB
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 2GB
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 2GB
Ok, I have deleted your new post as it is a duplicate. Please do not post duplicate thread.

Regards,

Jeff
Oct 6 '08 #4
It's OK now, thanks so much, also sorry for duplicate post.
Oct 6 '08 #5
eWish
Expert 512MB
So, did you figured out your problem?

--Kevin
Oct 6 '08 #6
numberwhun
Expert Mod 2GB
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 2GB
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.

Similar topics

28 posts views Thread by Benjamin Niemann | last post: by
10 posts views Thread by clueless_google@hotmail.com | last post: by
8 posts views Thread by Dimitri Furman | last post: by
7 posts views Thread by Niclas | last post: by
2 posts views Thread by jodyblau | last post: by
5 posts views Thread by paulo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.