in reply to Simple IF, IF, IF or ELSE

That doesn't quite work. Try it for coffee, and you get 'unknown'. Fix:
if ($punter eq 'coffee') { $drink = 'non alky'; } elsif ($punter eq 'beer' ) { $drink = 'alky'; } elsif ($punter eq 'whisky') { $drink = 'proper alky'; } else { $drink = 'unknown'; }
Alternative:
my %lookup = ( 'coffee' => 'non alky', 'beer' => 'alky', 'whisky' => 'proper alky', ); if (exists $lookup{$punter}) { $drink = $lookup{$punter}; } else { $drink = 'unknown'; }

Replies are listed 'Best First'.
Re^2: Simple IF, IF, IF or ELSE
by dsheroh (Monsignor) on Jun 28, 2006 at 22:02 UTC
    Just to compress your alternative method a little bit more:
    my %lookup = ( 'coffee' => 'non alky', 'beer' => 'alky', 'whisky' => 'proper alky', ); $drink = exists $lookup{$punter} ? $lookup{$punter} : 'unknown'; # or another option: # $drink = $lookup{$punter} || 'unknown';