in reply to Initializing a hash using conditions

I prefer moving the conditional out of the initial assignment, but that is a thoughtless prejudice of habit and society.

I recommend the inline ternary solutions that you've recieved. I post because those solve your immediate problem but don't address the fundamental problem with your code:

%hash = ( ( 'abc' => 7) if ( ! $i), );
The primary problem is that you are placing a statement where an expression is expected. A general solution to this problem is to use a do BLOCK that ends with the value you want.

%hash = ( do{ if ( $i) { abc => 7 } else { } }, );
Be well,
rir