hi all...i am newbie to perl...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...
while( condition1 && condition2 || condition3 ) { #statements; }
i want to count how many conditions are there inside the while and my output should be of like this...
while( 1 condition1 && 2 condition2 || 3 condition3 ) { #statements; }
i have written the code and it works fine for simple one.. my code....
open(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); }
but for complicated conditions like
while( ( condition1 && condition2 && condition3 ) || ( condition4 || condition5 && condition6 ) { #statements; }
am getting the output like
while( ( 1 condition1 && 2 condition2 && condition3 3 ) || ( 4 condition4 || 5 condition5 && condition6 ) )
which is not desired.... my intension is to count all the conditions regarding however complicated it is..... please help me... desired output may be
while( ( 1 condition1 && 2 condition2 && 3 condition3 ) || ( 4 condition4 || 5 condition5 && 6 condition6 ) )
since it has used 6 conditions inside... hence forth for any cases... please help me .....

In reply to How to count number of multiple logical conditions used in if,elseif or while in perl by loki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.