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

Re: if statement consolidation

by muba (Priest)
on Jun 27, 2012 at 15:48 UTC ( [id://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]; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found