http://www.perlmonks.org?node_id=996893


in reply to Re: Options with optional values and condititions
in thread Options with optional values and condititions

Careful ... if ($foo) probably-unintentionally checks for truth, such that a value of zero would fail the test.

Replies are listed 'Best First'.
Re^3: Options with optional values and condititions
by runrig (Abbot) on Oct 02, 2012 at 18:50 UTC
    if ($foo) probably-unintentionally checks for truth...
    It was intentional by me, though I don't know what the OP wants. From the docs:
    Using a colon ":" instead of the equals sign indicates that the option value is optional. In this case, if no suitable value is supplied, string valued options get an empty string '' assigned, while numeric options are set to 0.

    So yes, if you supply a value of "0" to a string option, you'll miss it. If you want to catch that situation you'll have to code for it. I often assume such strings are invalid in most practical situations.