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).
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|