Home United States USA — software Get Out Early With Perl Statement Modifiers

Get Out Early With Perl Statement Modifiers

156
0
SHARE

Learn how to avoid deeply-nested conditions in your code with guard clauses using Perl’s statement modifiers.
Join the DZone community and get the full member experience. When I first started writing Perl in my early 20’s, I tended to follow a lot of the structured programming conventions I had learned in school through Pascal, especially the notion that every function has a single point of exit. For example: This could get pretty convoluted, especially if I was doing something like validating multiple arguments. And at the time I didn’t yet grok how to handle exceptions with eval and die, so I’d end up with code like: What a mess. Want to count all those braces to make sure they’re balanced? This is sometimes called the arrow anti-pattern, with the arrowhead(s) being the most nested statement.

Continue reading...