in reply to Conditional within Hash definition
Or even:my $rain = 1; my %Weather = ( 'precipitation' => ($rain == 0) ? 'dry' : 'wet', );
The way to use the if/elsif construct:my $rain = 1; my %Weather = ( 'precipitation' => $rain ? 'wet' : 'dry', );
See perldoc for Conditional Operator and Compound Statements, and also strict and warningsmy $precipitation; if ($rain == 0) { $precipitation = 'dry'; } elsif ($rain == 1) { $precipitation = 'wet'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Conditional within Hash definition
by veryan (Initiate) on Jan 28, 2014 at 16:56 UTC |