http://qs321.pair.com?node_id=1005395


in reply to Replacing If Elsif Else with Hash

I would suggest putting this chunk into a routine. It provides some documentation, it becomes easier to modify behaviour in the future, because any changes are isolated within a short routine, and implementation details are separated from business logic.

use Readonly; Readonly my %BGCOLOR => ( Extreme => 'red', ... ); Readonly my $DEFAULT_BGCOLOR => 'grey'; sub get_bg_color { my ( $severity ) = @_; return $DEFAULT_BGCOLOR unless exists $BGCOLOR{$severity}; return$BGCOLOR{$severity}; } my $bg = get_bg_color( $condition );

edit - corrected typo $BGCOLOR => %BGCOLOR; thanks, Anon Monk!

As Occam said: Entia non sunt multiplicanda praeter necessitatem.