http://www.perlmonks.org?node_id=309692

In Java, it's easy to know how try { } catch { } block line up by using simple indentation rules:

try { // Do Stuff } catch (IOException e) { // Handle IO errors } catch (Exception e) { // Handle any other error }

The equivilent construct in Perl (without using modules) is to use an eval { }:

eval { # Do stuff }; if($@) { # Handle any errors }

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 Exception Error module (Update: I meant Error.pm here. Thanks Zed_Lopez.), but that module has issues with its implementation and should probably be avoided.

The next best solution that I'm putting forth is to break normal indentation rules:

eval { # Do stuff }; if(@$) { # Handle any errors }

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.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated