Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Conditional within Hash definition

by tangent (Parson)
on Jan 28, 2014 at 16:22 UTC ( [id://1072373]=note: print w/replies, xml ) Need Help??


in reply to Conditional within Hash definition

Using the ternary operator:
my $rain = 1; my %Weather = ( 'precipitation' => ($rain == 0) ? 'dry' : 'wet', );
Or even:
my $rain = 1; my %Weather = ( 'precipitation' => $rain ? 'wet' : 'dry', );
The way to use the if/elsif construct:
my $precipitation; if ($rain == 0) { $precipitation = 'dry'; } elsif ($rain == 1) { $precipitation = 'wet'; }
See perldoc for Conditional Operator and Compound Statements, and also strict and warnings

Replies are listed 'Best First'.
Re^2: Conditional within Hash definition
by veryan (Initiate) on Jan 28, 2014 at 16:56 UTC
    So many thanks - much appreciated!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-26 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found