As already mentioned, your code checks for falsity. If you considered false values โโnon-existent, you could use boolean or. This is probably not what you want.
$settingsHash{verbosity} = $optionalParamsRef->{verbosity} || $default;
But perhaps a certain degree is enough. This still does not check for existence, but if your hash does not contain undef values, this may be enough:
$settingsHash{verbosity} = $optionalParamsRef->{verbosity} // $default;
using the "new" defined or operator // instead of boolean or || . I know that these examples are not equivalent to the code you posted because they assign something, but, in my experience, this is often useful, so maybe this can help.
source share