Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Just another Perl shrine
 
PerlMonks  

Re: if else and not reachable coding style

by fergal (Chaplain)
on Mar 08, 2006 at 17:22 UTC ( [id://535275]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to if else and not reachable coding style

I'm a little unclear on what you're trying to achieve. Are you using a sub because this code will be called from multiple places or are you just using it because COND and the return values are too messy for a ternary?

If the latter then you might try

$value = do { if (COND) { 1; } else { 2; } };
which has the advantage of keeping the logic close to where it's used and not defining a once off sub.

Either way, the second construction with the die is kinda pointless as the die can never be reached.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://535275]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.