Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: Surprising result when using undef by swl
in thread Surprising result when using undef by davebaker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-20 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found