Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: if else and not reachable coding style

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


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
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-18 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found