You ran into a pet peeve of mine (at least twice in presented code):
There shall be no else after leaving enclosing scope (exit, die, return, last …)
When using if … else …, the code after that is to be executed always, that is why you have if/else. If however the first part ENDs with an exit of the enclosing scope, there is no need whatsoever for the else. Removing else, the braces and the indent, make the code easier to read and maintain.
if (expression) { … exit; } else { … … } => if (expression) { … exit; } … …
See for slides from a talk here and here/here:
sub foo { my $s = shift; if (defined $s) { if ($s ne "") { # # 150 lines of code # } else { die "String is empty"; } } else { die "String is null"; } } => sub foo { my $s = shift; unless (defined $s) { die "String is null"; } if ($s eq "") { die "String is empty"; } # # 150 lines of code # }
In reply to Re: Perl replacement for choice.com
by Tux
in thread Perl replacement for choice.com
by onelander
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |