Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Lazy conditional, skips assignment.

by roboticus (Chancellor)
on Mar 25, 2015 at 19:50 UTC ( [id://1121332]=note: print w/replies, xml ) Need Help??


in reply to Lazy conditional, skips assignment.

cheako:

If the first clause of an AND is false, or if the first clause of an OR is true, there's no reason for perl to evaluate the right side of the expression. Side effects in expressions often have issues like this.

In your case, it looks like you're just trying to pack too much stuff in a single conditional. When I look it over, I wonder what the heck it's doing. Yeah, I can figure it out, but I'd rather work on code that I can read, rather than decipher. Breaking it down into discrete units will make it simpler to read, and easier for you to debug, as well!

Update: I think your code is probably trying to do this (roughly):

our $cookingcounter = 350883; our $garlicbreadheadstart = 600; our $ovenempty = 0; sub hold_time { my $cookingcounter = shift; return 0 if $ovenempty and !$test; my $holdtime = $cookingcounter + 60*90 - 356400; return $holdtime if $holdtime > 0; $holdtime = $cookingcounter + ($garlicbreadstart - 60 * (60+15)) - + 356400; return $holdtime if $holdtime > 0; return 0; }

Update 2: After seeing hdb's response, I adjusted my code so it wouldn't return in test mode even when the oven is empty.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-23 19:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found