It is a matter of taste (and style), but I only use unless without the else-clause. If you have the else, then you could just as well use a normal if and get better readability - it's more like waht everyone is used to.
But in a standalone if (!(some_complicated_expression)) the use of unless lets you remove one pair of parenthesis and lets the poor smuck reading the code have one less thing to worry about.
I would rewrite your example as $value=20;
if ($divisor!=0){ #so long as the $divisor isn't equal to 0
$value=$value/$divisor; #go ahead and divide $value by $divisor
} else {
$divisor=1; #otherwise set $divisor to 1
}
Now the statement says the same as the comment (in your code it should have been #unless the $divisor isn't equal to 0 - 'so long' indicates a repetition IMHO).
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, 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, 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.
|
|