When doing my coding i've noticed i'm checking and chucking the input to my methods before the real logic of the module, rather than using a complex set of if then elsif's.
For example:
sub doSomething {
my $self = shift;
my $q = $self->query();
return "Invalid Login!" if ($q->param('login') =~ /^[\w\/\-]{0,32}
+$/);
#main guts of routine here...
return $outputOfRoutine;
}
I'll use the same construct with die, or croak as appropriate..
This works quite well for me as I can put all the semantic validation at the top of the routine and worry about other integrity/logic later on in the routine.
I'll never return from the "middle" of a routine as i find it makes debugging a little more difficult as there are multiple "areas" where the routine can be exited from. Beside the semantic validation at the top of the routine the exit will always be at the bottom before the }
Purists say there should only be one entry and one exit and anything else is obfu. What do you say?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.