Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
While attempting to convert the C code below, I was able to deduce where to block 3 loops with "curlies" as indicated by # new.
However, there are 7 places where the C program has an if statement or for loop with no obvious (to me) end. Indenting may suggest a block termination but this is only conjecture on my part and I cannot be certain the indenting is correct.
There are several C routines I want to convert with similar structures. Would a kind monk explain what rules C uses to terminate a block and then correct the code to show where the curly braces should go to make it work with Perl.
Thanks
01 sub standarization { # was standarization(void) 02 my(i,j,k); 03 for (i=1; i<=10; i++) # where does "for" end? 04 if (d[i][0]!=0) # where does "if" end? 05 for (k=1; k<24; k++) 06 { 07 d[0][k] += d[i][k]; 08 d[i][k] /= d[i][0]; 09 } 10 11 for (i=9; i<=18; i++) # where does "for" end? 12 if (psb[i][0]!=0) # where does "if" end? 13 for (k=11; k<=BUST; k++) 14 { # new 15 psb[i][k] /= psb[i][0]; 16 } # new 17 18 for (j=1; j<=10; j++) # where does "for" end? 19 if (s[j][0][0]!=0) { 20 for (i=12; i<=18; i++) { 21 if (s[j][i][0]!=0) # where does "if" end? 22 for (k=12; k<=BUST; k++) 23 { # new 24 s[j][i][k] /= s[j][i][0]; 25 } # new 26 27 if (s[j+10][i][0]!=0) # where does "if" end? 28 for (k=12; k<=BUST; k++) 29 { # new 30 s[j+10][i][k] /= s[j+10][i][0]; 31 } # new 32 s[j][i][0] /= s[j][0][0]; 33 s[j][i][1] /= s[j][0][0]; 34 s[j+10][i][0] /= s[j][0][0]; 35 s[j+10][i][1] /= s[j][0][0]; 36 } # end "for" line 20 37 38 for (k=17; k<=BUST; k++) { 39 s[j][0][k] /= s[j][0][0]; 40 s[j+10][0][k] /= s[j][0][0]; 41 } 42 } # end of "if" line 19 43 } # end of sub
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Convert loop and if constructs from C to Perl
by jbert (Priest) on Dec 16, 2006 at 09:20 UTC | |
|
Re: Convert loop and if constructs from C to Perl
by bart (Canon) on Dec 16, 2006 at 09:33 UTC | |
by syphilis (Archbishop) on Dec 16, 2006 at 10:33 UTC | |
by Anonymous Monk on Dec 16, 2006 at 11:10 UTC | |
by syphilis (Archbishop) on Dec 16, 2006 at 11:26 UTC | |
by Anonymous Monk on Dec 16, 2006 at 10:06 UTC | |
|
Re: Convert loop and if constructs from C to Perl
by syphilis (Archbishop) on Dec 16, 2006 at 09:55 UTC | |
|
Re: Convert loop and if constructs from C to Perl
by vladdrak (Monk) on Dec 16, 2006 at 09:10 UTC |