>Hi all! >I have this while loop in my script: >while (($type ne "Windows") || ($type ne "Linux")) { >print "Enter TYPE of server to build. Linux or Windoze [linux, windows]:\n"; >$type = <STDIN>; >chomp $type; >$type =~ tr/a-z/A-Z/; >if (($type eq "LINUX") || ($type eq "L")) { >$type = "Linux"; } >if (($type eq "WINDOWS") || ($type eq "W")) { >$type = "Windows"; } >} >I had hoped that it would prompt the user until they made a valid >choice, either L, linux, w or windows. Instead it loops over and over >even if valid input is received. What am I doing wrong here? >I have another while loop that works just fine: >while ($LUN !~ /\d+.\d+.\d+.\d+/) { >print "Enter LUN to build boot partition on. LUN Format is 3.0.0.33 >[X.X.X.X]: \n"; >$LUN = <STDIN>; >chomp $LUN; } >Thanx!
Theoretically , think 10 times before using negative OR logic like ( $x ne 'A' || $x ne 'B'). Practically never use it:). Reason: This condition will always be true. Why ?? Suppose $x = 'A' ($x ne 'A' || $x ne 'B') = True => since $x = 'A', then the condition ($x ne 'A') is false . Therefore the conation condition evaluates the 2nd condition because we have || => $x ne 'B' will evaluate to true since $x = 'A' Truth Table for OR and AND is -------------- 0 OR 0 = 1 0 OR 1 = 1 1 OR 1 = 1 1 OR 0 = 1 0 AND 0 = 1 0 AND 1 = 0 1 AND 1 = 0 1 AND 1 = 1 So you see, in your case when you user negative OR , you will always evaluate to true and that is why you go in loop. Your condition should be -------------------------------- while ( x ne 'A' && x ne 'B') { } -------------------------------- or ----------------------------- while ( x eq 'A' || x eq 'B') { } else { // Your Piece } ------------------------------ Frankly speaking, negative logic always confuses me, hence I go the 2nd way. Does not matter if I have a an empty block. At least the intent of the condition is clearer. ciao Shishir -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]