in reply to Initializing a hash using conditions

%hash = ( $i ? (abc => 7) : (), hk => 5, jk => 6, );

Replies are listed 'Best First'.
Re^2: Initializing a hash using conditions
by Random_Walk (Prior) on Feb 03, 2005 at 13:19 UTC

    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.

    Pereant, qui ante nos nostra dixerunt!