loki has asked for the wisdom of the Perl Monks concerning the following question:
i want to count how many conditions are there inside the while and my output should be of like this...while( condition1 && condition2 || condition3 ) { #statements; }
i have written the code and it works fine for simple one.. my code....while( 1 condition1 && 2 condition2 || 3 condition3 ) { #statements; }
but for complicated conditions likeopen(A,"e:\\a\\a.txt")or die; @a=<A>; close(A); $count=1; for($i=0;$i<scalar@a;$i++) { if($a[$i]=~m/while/g) { $line=$i; until($a[$line]=~/\{/g) { if($a[$line]=~/(.*)[\&&\||]/g){print"$count $a[$line]";$count++ +;} elsif($a[$line]=~/\(.*\)[\&&\||]/g){print"$count $a[$line]";$co +unt++;} else{print$a[$line];} $line++; } } last if($a[$line]=~/\{/g); }
am getting the output likewhile( ( condition1 && condition2 && condition3 ) || ( condition4 || condition5 && condition6 ) { #statements; }
which is not desired.... my intension is to count all the conditions regarding however complicated it is..... please help me... desired output may bewhile( ( 1 condition1 && 2 condition2 && condition3 3 ) || ( 4 condition4 || 5 condition5 && condition6 ) )
since it has used 6 conditions inside... hence forth for any cases... please help me .....while( ( 1 condition1 && 2 condition2 && 3 condition3 ) || ( 4 condition4 || 5 condition5 && 6 condition6 ) )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to count number of multiple logical conditions used in if,elseif or while in perl
by Marshall (Canon) on Dec 21, 2009 at 16:51 UTC | |
|
Re: How to count number of multiple logical conditions used in if,elseif or while in perl
by Anonymous Monk on Dec 21, 2009 at 14:06 UTC | |
by loki (Novice) on Dec 22, 2009 at 06:23 UTC | |
by Marshall (Canon) on Dec 24, 2009 at 15:33 UTC |