http://www.perlmonks.org?node_id=1005332


in reply to Replacing If Elsif Else with Hash

This will return 'grey' if you use a severity not defined in the hash:
my %bkcolor = ( 'Extreme' => 'red', 'Severe' => 'orange', 'Moderate' => 'yellow', 'Minor' => 'green', ); my $background = $bkcolor{$severity} // 'grey';

Replies are listed 'Best First'.
Re^2: Replacing If Elsif Else with Hash
by moritz (Cardinal) on Nov 24, 2012 at 08:59 UTC
Re^2: Replacing If Elsif Else with Hash
by johnfl68 (Scribe) on Nov 24, 2012 at 05:29 UTC

    Thank you very much for you time and help!

    John