Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: if statement consolidation

by muba (Priest)
on Jun 27, 2012 at 15:48 UTC ( #978706=note: print w/ replies, xml ) Need Help??


in reply to if statement consolidation

If your Perl is relatively modern, you could look into given/when. Another idea might to write a look-up hash and draw from that. I'm not saying it's the best idea, but at least it's an idea. Update: and a rather popular idea, too.

my %values_for_h => 1 => [1, 0, 9], 3 => [2, 1, 10], 5 => [3, 0, 11], 7 => [4, 1, 11], 10 => [5, 0, 5], 12 => [6, 1 6], 14 => [7, 0, 7], 16 => [8, 1, 8] ); if (exists $values_for_h{$h}) { $j = $h + $values_for_h{$h}->[0]; $p = $values_for_h{$h}->[1]; $v = $values_for_h{$h}->[2]; }


Comment on Re: if statement consolidation
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (15)
As of 2015-07-01 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (16 votes), past polls