Perl-Sensitive Sunglasses | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
In Java, it's easy to know how try { } catch { } block line up by using simple indentation rules:
The equivilent construct in Perl (without using modules) is to use an eval { }:
The problem is that it isn't immediately apparent that the if block is equivilent to a Java catch (i.e., something that catches errors, as opposed to one of the infinate number of other uses for an if statement). To a novice Perl coder, it's just an if statement with a weird punctuation variable in the conditional. Even an experianced Perl coder needs to read more information to know what it does, since the Human brain tends to read an entire word at a time. One could use the The next best solution that I'm putting forth is to break normal indentation rules:
By cuddling the if, and being consistant in not cuddling anywhere else (you are being consistant, right?), you're saying "this if statement is related to the eval above it". To a novice, it still has a weird punctuation variable next to it, but at least they're hinted in as to its true function. To an experianced one, they can recognize the construct without extra intepretation at the HumanOS layer. ---- : () { :|:& };: Note: All code is untested, unless otherwise stated In reply to Style Point: Catching eval { } errors by hardburn
|
|