You could write the operator yourself:
sub assign_if_defined { $_[0] = $_[1] if defined $_[1]; } assign_if_defined($a->{'b'}, $b);
By the way, I'm using defined since you said you didn't want empty keys. Checking for truthfullness (as you have been doing) removes both empty and false keys. Just remove the word defined for a truth test.
In reply to Re^3: Shortcut operator for $a->{'b'}=$b if $b;
by ikegami
in thread Shortcut operator for $a->{'b'}=$b if $b;
by rokadave
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |