http://qs321.pair.com?node_id=11128667


in reply to Surprising result when using undef

undef is not the same as zero.

I see a couple of options you could use.

use 5.010; my $is_dev_mode = $param->{is_dev_mode} // 1;

Or for perls older than 5.10:

my $is_dev_mode = defined $param->{is_dev_mode} ? $param->{is_dev_mode +} : 1;

And if you want to get a bit more obtuse and do all the value handling on one line then you can use the double negative ("bang bang" operator). That will convert any non-zero (or true) value to a 1, and any false value to perl's false. Then that can be converted to a zero.

# it would likely help your future self to add a comment here if you +do this my $is_dev_mode = !!$param->{is_dev_mode} || 0;

Another alternative is to use a boolean flag to test for non-dev mode, instead of dev mode. Then you only need to check for truthiness of the passed flag to determine whether to send the emails or not. That avoids all the value checking and changing, simplifying your code. It also means that if the flag is not passed with a true value then the emails will not be sent.