title: How can I count number of logical conditions used in if,elseif or while in Perl?
body: <p>i have a while,if,elseif statements in a file with multipe conditions inside 
    it... it is a C language...the format is mentioned below is standard for all the 
    multiple conditions.So no worries about the indendation.The only problem is to check how 
    many conditions are there and list as per output format that i have described....
    eg if my C file have a code... </p>
  
  <pre><code>while(
        condition1 &amp;&amp;
        condition2 ||
        condition3
       )
  {
    #statements; 
  }
  </code></pre>
  
  <p>i want to count how many conditions are there inside the while and my output should be<br>
    of like this...</p>
  
  <pre><code>  while(
    1    condition1 &amp;&amp;
    2    condition2 ||
    3    condition3
       )
  {
    #statements; 
  }
  </code></pre>
  
  <p>i have written the code and it works fine for simple one.. my code....</p>
  
  <pre><code>open(A,"e:\\a\\a.txt")or die;
  @a=&lt;A&gt;;
  close(A);
  $count=1;
  for($i=0;$i&lt;scalar@a;$i++)
  {
    if($a[$i]=~m/while/g)
    {
      $line=$i;
      until($a[$line]=~/\{/g)
      {
         if($a[$line]=~/(.*)[\&amp;&amp;\||]/g){print"$count $a[$line]";$count++;}  
         elsif($a[$line]=~/\(.*\)[\&amp;&amp;\||]/g){print"$count $a[$line]";$count++;}  
         else{print$a[$line];}
         $line++;
      }
    }
   last if($a[$line]=~/\{/g);
  }
  </code></pre>
  
  <p>but for complicated conditions like</p>
  
  <pre><code>while(
          ( 
           condition1 &amp;&amp;
           condition2 &amp;&amp;
           condition3
          ) ||
          (
            condition4 ||
            condition5 &amp;&amp;
            condition6
           )
  
  {
    #statements;
  }
  </code></pre>
  
  <p>am getting the output like </p>
  
  <pre><code>while(
          ( 
         1  condition1 &amp;&amp;
         2  condition2 &amp;&amp;
            condition3
         3 ) ||
          (
         4  condition4 ||
         5  condition5 &amp;&amp;
            condition6
           )
  </code></pre>
  
  <p>which is not desired.... my intension is to count all the conditions regarding however complicated it is..... please help me...</p>
  
  <p>desired output may be </p>
  
  <p>while(
          ( 
             1  condition1 &amp;&amp;
             2  condition2 &amp;&amp;
             3  condition3
          )   ||
          (
             4  condition4 ||
             5  condition5 &amp;&amp;
             6  condition6
          )
       )
  since it has used 6 conditions inside... hence forth for any cases.</p>