Trying to formulate the correct if condition test. I want to take action only if both floor locks are online (not reporting eStatusLockUnknown). The two tests I've tried are below. When debugging, I can see that both floor locks are reporting *.lockState = eStatusLockIndeterminate, but I'm not falling into my action code. Microchip xc16 v1.25 compiler.
if (( sLockStatus[eHeadFloorLock].lockState == ( eStatusLockIndeterminate
|| eStatusLockEngaged || eStatusLockStowed || eStatusLockFullyEngaged ))
&& ( sLockStatus[eFootFloorLock].lockState == ( eStatusLockIndeterminate || eStatusLockEngaged || eStatusLockStowed || eStatusLockFullyEngaged )))
{
// take action
}
if (( sLockStatus[eHeadFloorLock].lockState == eStatusLockIndeterminate )
|| ( sLockStatus[eHeadFloorLock].lockState == eStatusLockEngaged )
|| ( sLockStatus[eHeadFloorLock].lockState == eStatusLockStowed )
|| ( sLockStatus[eHeadFloorLock].lockState == eStatusLockFullyEngaged )
&& ( sLockStatus[eFootFloorLock].lockState == eStatusLockIndeterminate )
|| ( sLockStatus[eFootFloorLock].lockState == eStatusLockEngaged )
|| ( sLockStatus[eFootFloorLock].lockState == eStatusLockStowed )
|| ( sLockStatus[eFootFloorLock].lockState == eStatusLockFullyEngaged ))
{
// take action
}
First is wrong, because you are doing || on the constants and not on the conditions.
Second is wrong, since && binds more tightly than ||. You need parenthesis around the outermost || conditions.
Following should do what you want.
LockState headLockState = sLockStatus[eHeadFloorLock].lockState;
LockState footLockState = sLockStatus[eHeadFloorLock].lockState;
if (( headLockState == eStatusLockIndeterminate
|| headLockState == eStatusLockEngaged
|| headLockState == eStatusLockStowed
|| headLockState == eStatusLockFullyEngaged )
&& ( footLockState == eStatusLockIndeterminate
|| footLockState == eStatusLockEngaged
|| footLockState == eStatusLockStowed
|| footLockState == eStatusLockFullyEngaged ))
Related
I am using the following script template to process a tab-separated text file:
while IFS=$'\t' read -r column1 column2 column3 ; do
printf "%b\n" "column1<${column1}>"
printf "%b\n" "column2<${column2}>"
printf "%b\n" "column3<${column3}>"
done < "myfile"
Can I still access the entire line via some internal variable?
Purpose: The text files are file indexes of external drives created in another script with
find "$1" \( -size +40k -fprintf ~/Documents/fs/${1}.txt '%CY-%Cm-%Cd-%CH-%CM \t %-10s \t %h \t %f\n' \)
I want to split the lines into separate files according to the file types (video, audio, pictures, archives, other).
Of course I can reassemble the original line by using all of the field variables, but is there a more direct way? Currently my script goes sth like this:
while IFS=$'\t' read -r fdate fsize ffolder filename ; do
f_ext=${filename##*.}
f_ext=${f_ext,,}
if [[ "$f_ext" == "jpg" || "$f_ext" == "jpeg" || "$f_ext" == "gif" || "$f_ext" == "png" || "$f_ext" == "bmp" || "$f_ext" == "cbr" || "$f_ext" == "psd" || "$f_ext" == "jp2" || "$f_ext" == "tif" || "$f_ext" == "tiff" ]];then
echo -e "$fdate\t$fsize\t$ffolder\t$filename" >> "$fdir/${txtfnpure}Pics.txt"
elif [[ "$f_ext" == "mka" || "$f_ext" == "m4a" || "$f_ext" == "aac" || "$f_ext" == "mp3" || "$f_ext" == "ogg" || "$f_ext" == "mp2" || "$f_ext" == "wav" || "$f_ext" == "wave" || "$f_ext" == "ac3" || "$f_ext" == "wma" || "$f_ext" == "flac" || "$f_ext" == "fla" || "$f_ext" == "aiff" || "$f_ext" == "aif" ]];then
...
Workaround with bash:
while IFS='' read -r line; do
IFS=$'\t' read -r column1 column2 column3 <<< "$line"
echo "complete line: $line"
printf "%b\n" "column1<${column1}>"
printf "%b\n" "column2<${column2}>"
printf "%b\n" "column3<${column3}>"
done < "myfile"
I have a small issue and i hope your your help.
The problem is as fallow:
I need to track a huge log and more exactly a column.
In this column i have some integer values in a rage between 103 and 17430.
Example of original file
....
402
402
402
402
402
402
402
402
402
1917
402
402
402
402
402
667
942
342
990
444
.....
I must replace each row of my original file with an alternative index number.
Example:
....
3
3
3
3
3
3
3
3
3
3
3
3
7
3
3
3
3
9
5
3
1
....
Initially i tried to use sed in order to look for my string and replace it accordingly. First I extract only the data that i need then I start replacing:
col1=$(csvtool col 2 /mypath/log.csv >index )
sed -i 's/103/3 /g' index
sed -i 's/104/3 /g' index
sed -i 's/105/3 /g' index
sed -i 's/106/3 /g' index
........................
The problem is that it takes way to long to perform the changes due to large file and clearly inefficient method.
I was thinking to do something like:
csvtool col 2 /mypath/log.csv >index
for X in range (103 , 106 ) or (306-997):
print (3)
done < index
My problem is that I not proficient with loops (yet). I`m isolating the data that I need by creating the index file and I must read each row for my X value. My indexes are on specific ,sometimes multiple, ranges of my X values. Index number 3 can be taken by any X between 103 and 106 but 306-997 also.
In order to speed up the process I was thinking to use the loops and fit my X into a specific range, rather then comparing with each possible value. Any help how can I write my loops? or you have a better idea?
With the help of Cyrus I manage to write the fallowing corrected code:
csvtool col 2 /my/path/to/List.csv >tmp
awk '($0>=363 && $0<=499) || ($0>=4645 && $0<=4646) {$0="0"}1' tmp
awk '($0>=2174 && $0<=2193) {$0="1"}1' tmp
awk '($0=500) || ($0>=12308 && $0<=12356) {$0="2"}1' tmp
awk '($0>=103 && $0<=220) || ($0>=252 && $0<=299) || ($0>=1980 && $0<=1986) || ($0>=2921 && $0<=2922) {$0="3"}1' tmp
awk '($0>=221 && $0<=251) || ($0>=8085 && $0<=8091) || ($0=8350) || ($0>=12809 && $0<=12945) || ($0>=16834 && $0<=17033) {$0="4"}1' tmp
awk '($0>=300 && $0<=362) || ($0=522) || ($0>=2923 && $0<=2925) || ($0>=3441 && $0<=3442) || ($0=4644)|| ($0>=5677 && $0<=5695) || ($0>=8082 && $0<=8083)|| ($0>=8093 && $0<=8349) || ($0>=12946 && $0<=12947) || ($0>=21986 && $0<=13215) || ($0>=13309 && $0<=13311) {$0="5"}1' tmp
awk '($0>=501 && $0<=504) || ($0>=566 && $0<=600) || ($0>=613 && $0<=637) || ($0>=2015 && $0<=2040) || ($0>=2103 && $0<=2126) || ($0>=2373 && $0<=2374) || ($0>=3828 && $0<=4125) || ($0>=4237 && $0<=4636) || ($0>=4647 && $0<=4889) || ($0>=4991 && $0<=5676) || ($0>=5696 && $0<=5705) || ($0>=6502 && $0<=6595) || ($0>=8429 && $0<=8460) || ($0>=8552 && $0<=8699) || ($0>=10487 && $0<=10977) || ($0>=11326 && $0<=11617) || ($0>=11688 && $0<=11815) || ($0>=11844 && $0<=11938) || ($0>=12490 && $0<=12597) || ($0>=12973 && $0<=12982) || ($0>=13367 && $0<=13414) {$0="6"}1' tmp
awk '($0>=523 && $0<=548) || ($0>=555 && $0<=565) || ($0>=2005 && $0<=2014) || ($0>=2041 && $0<=2063) || ($0>=2091 && $0<=2102) || ($0=2394) || ($0>=2407 && $0<=2411) || ($0>=2926 && $0<=3008) || ($0>=3443 && $0<=3473) || ($0>=3486 && $0<=3813) || ($0>=4132 && $0<=4144) || ($0>=4637 && $0<=4643) || ($0>=4916 && $0<=4981) || ($0>=5711 && $0<=5741) || ($0>=6403 && $0<=6405) || ($0>=6415 && $0<=6466) || ($0>=6701 && $0<=7002) || ($0>=7035 && $0<=7048) || ($0>=8426 && $0<=8428) || ($0>=8496 && $0<=8541) || ($0>=8857 && $0<=9323) || ($0>=9429 && $0<=9618) || ($0>=9674 && $0<=9789) || ($0>=9802 && $0<=9811) || ($0>=9850 && $0<=10009) || ($0>=10131 && $0<=10136) || ($0>=10396 && $0<=10402) || ($0>=11000 && $0<=11175) || ($0=11618) || ($0>=12100 && $0<=12111) || ($0>=12212 && $0<=12219) || ($0=12489) || ($0>=12807 && $0<=12808) || ($0=12983) || ($0>=14616 && $0<=14627) || ($0>=15723 && $0<=15897) {$0="7"}1' tmp
awk '($0=521) || ($0=554) || ($0>=601 && $0<=612) || ($0>=651 && $0<=708) || ($0>=1905 && $0<=1942) || ($0>=1949 && $0<=1979) || ($0>=1987 && $0<=1993) || ($0>=2259 && $0<=2278) || ($0>=2352 && $0<=2362) || ($0>=2395 && $0<=2406) || ($0>=2412 && $0<=2449) || ($0>=2673 && $0<=2919) || ($0>=3009 && $0<=3016) || ($0>=3814 && $0<=3827) || ($0>=4126 && $0<=4131) || ($0>=4982 && $0<=4990) || ($0>=5706 && $0<=5710) || ($0>=6012 && $0<=6181) || ($0>=6285 && $0<=6339) || ($0>=6409 && $0<=6411) || ($0>=6596 && $0<=6700) || ($0>=7191 && $0<=7424) || ($0=8081) || ($0>=8550 && $0<=8551) || ($0>=8700 && $0<=8716) || ($0>=9324 && $0<=9326) || ($0>=9619 && $0<=9624) || ($0=9729) || ($0>=10018 && $0<=10064) || ($0>=10115 && $0<=10126) || ($0>=10198 && $0<=10386) || ($0=10486) || ($0>=12112 && $0<=12115) || ($0>=12209 && $0<=12211) {$0="8"}1' tmp
awk '($0>=489 && $0<=498) || ($0>=505 && $0<=520) || ($0>=549 && $0<=553) || ($0>=638 && $0<=650) || ($0>=709 && $0<=1904) || ($0>=1943 && $0<=1948) || ($0>=1994 && $0<=2004) || ($0>=2064 && $0<=2090) || ($0>=2127 && $0<=2173) || ($0>=2194 && $0<=2258) || ($0>=2279 && $0<=2351) || ($0>=2363 && $0<=2372) || ($0=2393) || ($0>=2450 && $0<=2672) || ($0>=3474 && $0<=3485) || ($0>=4145 && $0<=4236) || ($0>=4890 && $0<=4915) || ($0>=5742 && $0<=6011) || ($0>=7003 && $0<=7034) || ($0>=7049 && $0<=7295) || ($0>=7425 && $0<=8080) || ($0=8084) || ($0>=8352 && $0<=8425) || ($0>=8461 && $0<=8495) || ($0>=8542 && $0<=8549) || ($0>=8717 && $0<=8856) || ($0>=9327 && $0<=9428) || ($0>=9625 && $0<=9673) || ($0>=9790 && $0<=9791) || ($0>=9793 && $0<=9801) || ($0>=9812 && $0<=9849) || ($0>=10010 && $0<=10017) || ($0>=10065 && $0<=10114) || ($0>=10128 && $0<=10130) || ($0>=10137 && $0<=10197) || ($0>=10387 && $0<=10395) || ($0>=10403 && $0<=10485) || ($0>=10978 && $0<=10999) || ($0>=11176 && $0<=11325) || ($0>=11620 && $0<=11687) || ($0>=11816 && $0<=11843) || ($0>=11939 && $0<=12099) || ($0>=12116 && $0<=12208) || ($0>=12220 && $0<=12307) || ($0>=12357 && $0<=12488) || ($0>=12598 && $0<=12806) || ($0>=12948 && $0<=12972) || ($0>=13216 && $0<=13306) || ($0>=13312 && $0<=13366) || ($0>=13415 && $0<=14615) || ($0>=14628 && $0<=15722) || ($0>=15989 && $0<=16833) || ($0>=17402 && $0<=17431) {$0="9"}1' tmp
Unfortunately the output is all "9". Any help?
awk '($0>=103 && $0<=106) || ($0>=306 && $0<=977) {$0="3"}1' file
Output:
3
3
3
3
3
3
3
3
3
1917
3
3
3
3
3
3
3
3
990
3
I am trying to generate all possible 16-digit decimal numbers.
I know that this will require a lot of storage, so I have tried to reduce the numbers by removing all numbers that the 6th digit is not equal to the 3rd digit - 1. I have also made sure that no four consecutive digits are equal.
The problem comes when I am trying to remove all generated numbers which contain more than eight zeroes. For instance, I don't want to print the following 0000150000100210 or 0001000200343.
Below is my Perl code for the above. I declare a global variable $A that is incremented each time any of the 16 digits is a zero, and then not to print the number when $A is more than eight. But it fails to work please help
#!/usr/bin/perl
$A=0;
for($a=0){
if($a==0){$A++;if($A>16){$A=0;}}
for($b=0;$b<6;$b++){
if($b==0){$A++;if($A>16){$A=0;}}
for($c=0;$c<6;$c++){
if($c==0){$A++;if($A>16){$A=0;}}
for($d=0;$d<6;$d++){
if($d==0){$A++;if($A>16){$A=0;}}
for($e=0;$e<6;$e++){
if($e==0){$A++;if($A>16){$A=0;}}
for($f=0;$f<6;$f++){
#check if all Numbers a-i are equal
#No 8 numbers can be the same in the same order
$Fc=$c-1;
if($Fc==-1){$Fc=5;}
#print "F==$Fc\n";
if($a==0&&$b==0&&$c==0&&$d==0&&$e==0&&$f==0||$a==0&&$b==0&&$c==0&&$d==0&&$e==0||$a==1&&$b==1&&$c==1&&$d==0&&$e==1&&f==1||$a==1&&$b==1&&$c==1&&$d==1&&$e==1||$a==2&&$b==2&&$c==2&&$d==2&&$e==2||$a==2&&$b==2&&$c==2&&$d==2&&$e==2
&&$f==2||$a==3&&$b==3&&$c==3&&$d==3&&$e==3||$a==3&&$b==3&&$c==3&&$d==3&&$e==3&&$f==3||$a==4&&$b==4&&$c==4&&$d==4&&$e==4||$a==4&&$b==4&&$c==4&&$d==4&&$e==4&&$f==4||$a==5&&$b==5&&$c==5&&$d==5&&$e==5||$a==5&&$b==5&&$c==5&&$d==5&&$e==5&&$f==5
){}
else{
if($f==0){$A++;if($A>16){$A=0;}}
#print "$a$b$c$d$e$Fc\n"
for($g=0;$g<6;$g++){
if($g==0){$A++;if($A>16){$A=0;}}
for($h=0;$h<6;$h++){
if($h==0){$A++;if($A>16){$A=0;}}
for($i=0;$i<6;$i++){
if($i==0){$A++;if($A>16){$A=0;}}
for($j=0;$j<6;$j++){
if($j==0){$A++;if($A>16){$A=0;}}
for($k=0;$k<6;$k++){
if($k==0){$A++;if($A>16){$A=0;}}
for($l=0;$l<6;$l++){
if($g==0&&$h==0&&$i==0&&$j==0&&$k==0&&$l==0||$g==0&&$h==0&&$i==0&&$j==0&&$k==0||$g==1&&$h==1&&$i==1&&$j==0&&$k==1&&$l==1||$g==1&&$h==1&&$i==1&&$j==1&&$k==1||$g==2&&$h==2&&$i==2&&$j==2&&$k==2
&&$l==2||$g==2&&$h==2&&$i==2&&$j==2&&$k==2||$g==3&&$h==3&&$i==3&&$j==3&&$k==3&&$l==3||$g==3&&$h==3&&$i==3&&$j==3&&$k==3||$g==4&&$h==4&&$i==4&&$j==4&&$k==4&&$l==4||$g==4&&$h==4&&$i==4&&$j==4&&$k==4||$g==5&&$h==5&&$i==5&&$j==5&&$k==5&&$l==5||$g==5&&$h==5&&$i==5&&$j==5&&$k==5
){}
else{
if($l==0){$A++;if($A>16){$A=0;}}
for($m=0;$m<6;$m++){
if($m==0){$A++;if($A>16){$A=0;}}
for($n=0;$n<6;$n++){
if($n==0){$A++;if($A>16){$A=0;}}
for($o=0;$o<6;$o++){
if($o==0){$A++;if($A>16){$A=0;}}
for($p=0;$p<6;$p++){
if($p==0){$A++;if($A>16){$A=0;}}
if($l==0&&$m==0&&$n==0&&$o==0&&$p==0||$l==0&&$m==0&&$n==0&&$o==0||$l==1&&$m==1&&$n==1&&$o==1&&$p==1||$l==1&&$m==1&&$n==1&&$o==1||$l==2&&$m==2&&$n==2&&$o==2&&$p==2||$l==2&&$m==2&&$n==2&&$o==2||$l==3&&$m==3&&$n==3&&$o==3&&$p==3||$l==3&&$m==3&&$n==3&&$o==3||$l==4&&$m==4&&$n==4&&$o==4&&$p==4||$l==4&&$m==4&&$n==4&&$o==4||$l==5&&$m==5&&$n==5&&$o==5&&$p==5||$l==5&&$m==5&&$n==5&&$o==5){}else{
#print "$A\n";
if($A>8){}
else{
print "$a$b$c$d$e$Fc$g$h$i$j$k$l$m$n$o$p\n"#Print The Generated Numbers
}
}}}}}}}}}}}}}}}}}}}
Updated to reveal program structure
#!/usr/bin/perl
$A = 0;
for ( $a = 0 ) {
if ( $a == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $b = 0 ; $b < 6 ; $b++ ) {
if ( $b == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $c = 0 ; $c < 6 ; $c++ ) {
if ( $c == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $d = 0 ; $d < 6 ; $d++ ) {
if ( $d == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $e = 0 ; $e < 6 ; $e++ ) {
if ( $e == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $f = 0 ; $f < 6 ; $f++ ) {
#check if all Numbers a-i are equal
#No 8 numbers can be the same in the same order
$Fc = $c - 1;
if ( $Fc == -1 ) {
$Fc = 5;
}
#print "F==$Fc\n";
if ( $a == 0 && $b == 0 && $c == 0 && $d == 0 && $e == 0 && $f == 0
|| $a == 0 && $b == 0 && $c == 0 && $d == 0 && $e == 0
|| $a == 1 && $b == 1 && $c == 1 && $d == 0 && $e == 1 && f == 1
|| $a == 1 && $b == 1 && $c == 1 && $d == 1 && $e == 1
|| $a == 2 && $b == 2 && $c == 2 && $d == 2 && $e == 2
|| $a == 2 && $b == 2 && $c == 2 && $d == 2 && $e == 2 && $f == 2
|| $a == 3 && $b == 3 && $c == 3 && $d == 3 && $e == 3
|| $a == 3 && $b == 3 && $c == 3 && $d == 3 && $e == 3 && $f == 3
|| $a == 4 && $b == 4 && $c == 4 && $d == 4 && $e == 4
|| $a == 4 && $b == 4 && $c == 4 && $d == 4 && $e == 4 && $f == 4
|| $a == 5 && $b == 5 && $c == 5 && $d == 5 && $e == 5
|| $a == 5 && $b == 5 && $c == 5 && $d == 5 && $e == 5 && $f == 5 ) {
}
else {
if ( $f == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
#print "$a$b$c$d$e$Fc\n"
for ( $g = 0 ; $g < 6 ; $g++ ) {
if ( $g == 0 ) {
$A++;
if ( $A > 16 ) { $A = 0; }
}
for ( $h = 0 ; $h < 6 ; $h++ ) {
if ( $h == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $i = 0 ; $i < 6 ; $i++ ) {
if ( $i == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $j = 0 ; $j < 6 ; $j++ ) {
if ( $j == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $k = 0 ; $k < 6 ; $k++ ) {
if ( $k == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $l = 0 ; $l < 6 ; $l++ ) {
if ( $g == 0 && $h == 0 && $i == 0 && $j == 0 && $k == 0 && $l == 0
|| $g == 0 && $h == 0 && $i == 0 && $j == 0 && $k == 0
|| $g == 1 && $h == 1 && $i == 1 && $j == 0 && $k == 1 && $l == 1
|| $g == 1 && $h == 1 && $i == 1 && $j == 1 && $k == 1
|| $g == 2 && $h == 2 && $i == 2 && $j == 2 && $k == 2 && $l == 2
|| $g == 2 && $h == 2 && $i == 2 && $j == 2 && $k == 2
|| $g == 3 && $h == 3 && $i == 3 && $j == 3 && $k == 3 && $l == 3
|| $g == 3 && $h == 3 && $i == 3 && $j == 3 && $k == 3
|| $g == 4 && $h == 4 && $i == 4 && $j == 4 && $k == 4 && $l == 4
|| $g == 4 && $h == 4 && $i == 4 && $j == 4 && $k == 4
|| $g == 5 && $h == 5 && $i == 5 && $j == 5 && $k == 5 && $l == 5
|| $g == 5 && $h == 5 && $i == 5 && $j == 5 && $k == 5 ) {
}
else {
if ( $l == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $m = 0 ; $m < 6 ; $m++ ) {
if ( $m == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $n = 0 ; $n < 6 ; $n++ ) {
if ( $n == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $o = 0 ; $o < 6 ; $o++ ) {
if ( $o == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
for ( $p = 0 ; $p < 6 ; $p++ ) {
if ( $p == 0 ) {
$A++;
if ( $A > 16 ) {
$A = 0;
}
}
if ( $l == 0 && $m == 0 && $n == 0 && $o == 0 && $p == 0
|| $l == 0 && $m == 0 && $n == 0 && $o == 0
|| $l == 1 && $m == 1 && $n == 1 && $o == 1 && $p == 1
|| $l == 1 && $m == 1 && $n == 1 && $o == 1
|| $l == 2 && $m == 2 && $n == 2 && $o == 2 && $p == 2
|| $l == 2 && $m == 2 && $n == 2 && $o == 2
|| $l == 3 && $m == 3 && $n == 3 && $o == 3 && $p == 3
|| $l == 3 && $m == 3 && $n == 3 && $o == 3
|| $l == 4 && $m == 4 && $n == 4 && $o == 4 && $p == 4
|| $l == 4 && $m == 4 && $n == 4 && $o == 4
|| $l == 5 && $m == 5 && $n == 5 && $o == 5 && $p == 5
|| $l == 5 && $m == 5 && $n == 5 && $o == 5 ) {
}
else {
#print "$A\n";
if ( $A > 8 ) {
}
else {
print "$a$b$c$d$e$Fc$g$h$i$j$k$l$m$n$o$p\n" #Print The Generated Numbers
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
If I understand you correctly then all that code is just to avoid printing numbers that have more than eight zeroes
You can do that like this
my $credit_card_number = "$a$b$c$d$e$Fc$g$h$i$j$k$l$m$n$o$p";
print $credit_card_number, "\n" unless $credit_card_number =~ tr/0// > 8;
But I still think your enterprise is a fruitless one
The problem I am experience involves multiple IF statements. For some reason the script is validating against the code below even with the settings as follows:
SSLSite is Defined as N
SSLOnly is Undefined
Subdomain is Defined as N
if ([[ $SSLSite == y* || $SSLSite == Y* ]] && [[ $SSLOnly == n* || $SSLOnly == N* ]] && [[ $Subdomain == n* ]] || [[ $Subdomain == N* ]])
Any ideas?
Thanks.
Your long if condition can be shortened to:
[[ "$SSLSite" == [yY]* && "$SSLOnly" == [nN]* && "$Subdomain" == [nN]* ]]
To directly answer your question, the problem is your last condition: [[ $Subdomain == n* ]] || [[ $Subdomain == N* ]].
The || here is not grouped inside the [[ .. ]] like in the other clauses. This gives you
(A || B) && (C || D) && (E) || (F)
where you wanted
(A || B) && (C || D) && (E || F)
The former expression is true if F alone is true, which is why it's validating when Subdomain=N
You can solve it by making the last clause [[ $Subdomain == n* || $Subdomain == N* ]] instead, but clearly anubhava's syntax is better.
How could I go about simplifying an arbitrarily complex boolean expression?
For example:
!(!a && !b || !a && b || a && !b) && !(!a && !b || !a && b || a && !b) ||
!(!a && !b || !a && b || a && !b) && (!a && !b || !a && b || a && !b) ||
(!a && !b || !a && b || a && !b) && !(!a && !b || !a && b || a && !b)
Is an extremely verbose way of saying:
a && b
I could just about do this manually by using boolean laws intuitively. Is there a programmatic approach?
How does Wolfram Alpha do it?
thats simple boolean algebra
see :
http://en.wikipedia.org/wiki/Binary_decision_diagram
http://en.wikipedia.org/wiki/Circuit_minimization
http://en.wikipedia.org/wiki/Karnaugh_map