Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: unless statements

by htoug (Deacon)
on Feb 08, 2005 at 11:09 UTC ( #429005=note: print w/ replies, xml ) Need Help??


in reply to unless statements

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).


Comment on Re: unless statements
Select or Download Code
Re^2: unless statements
by Anonymous Monk on Jul 01, 2005 at 16:15 UTC
    Hello , well i think unless is a loop and things like : if ($divisor!=0){ doesn't work rather than using unless if will procedes the action for one time but unless will keep procedes the same things unless the statment goes wrong that's what i think

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://429005]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2014-09-19 17:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (144 votes), past polls