Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Syntax errors with {s

by nimdokk (Vicar)
on Oct 11, 2004 at 10:01 UTC ( [id://398123]=note: print w/replies, xml ) Need Help??

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.



Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://398123]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-06-24 14:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.