in reply to Syntax errors with {s

As people have already mentioned the problem with closing braces, I'll simply mention another technique I use to help prevent that problem. Whenever I open a brace (as with an if-statement), I close it right away (before inserting any code) and put a comment on the line with the closing brace - indicating which brace it is supposed to be close (helpful with nested if statements). For example:

if ($var < 0) { <do something> if ($var2 == 1) { <do something else> }#close second if } elsif ($var == 0) { <do this other thing> } else { <do something completely different> }#close first if

Its really a matter of preference, find something that works and stick with it. Keeping things indented and in line helps as well. Marking the closing braces can be used with for loops, code blocks or anything like that.

Replies are listed 'Best First'.
Re^2: Syntax errors with {s
by Prior Nacre V (Hermit) on Oct 11, 2004 at 10:25 UTC

    That's precisely what I do except I extend that idea to include all paired characters.

    I very rarely get any syntax errors using this method.

    It is also independent of the programmer's choice of code layout.

    Regards,

    PN5