in reply to &&= vivify keys?

$x{$k} &&= $v;

I expected the previous code to modify the hash only if the key is already there (and with a true value), or leave the hash untouched otherwise.

The problem is that your code is testing the value of the hash.    In order to test the hash key you have to use the exists operator.    From your description you want something like this:

$x{$k} = $v if exists $x{$k} && $k;

Replies are listed 'Best First'.
Re^2: &&= vivify keys?
by ikegami (Patriarch) on Apr 18, 2012 at 21:21 UTC

    The OP does indeed want to test the value ("and with a true value"). The following would serve his needs:

    $x{a} = 1 if !$x{a};