a conditional case

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akyuceisik
    New Member
    • Sep 2008
    • 6

    a conditional case

    Code:
    $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?
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    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

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      Ok, so you are aware of what I was speaking about in my last post, here is how you should have presented your code:

      Code:
      $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');
      }
      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:

      Code:
      use strict;
      use warnings;
      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

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        Ok, I have deleted your new post as it is a duplicate. Please do not post duplicate thread.

        Regards,

        Jeff

        Comment

        • akyuceisik
          New Member
          • Sep 2008
          • 6

          #5
          It's OK now, thanks so much, also sorry for duplicate post.

          Comment

          • eWish
            Recognized Expert Contributor
            • Jul 2007
            • 973

            #6
            So, did you figured out your problem?

            --Kevin

            Comment

            • numberwhun
              Recognized Expert Moderator Specialist
              • May 2007
              • 3467

              #7
              Originally posted by eWish
              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

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                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.

                Comment

                Working...