in reply to Re: Initializing a hash using conditions
in thread Initializing a hash using conditions
Anon Monk++, nice neat solution that does not create the key abc unless the condition evaluates true. However I think you switched the logic of the OP
# OP %hash = ( ('abc' => 7) if (! $i), # abc if not $i 'hk' => 5, 'jk' => 6 # Anonymonk %hash = ( $i ? (abc => 7) : (), # create abc if $i hk => 5, jk => 6, ); # /me thinks %hash = ( $i ? () : (abc => 7), # create abc if not $i hk => 5, jk => 6, );
Cheers,
R.
|
|---|