I am defining a method with an optional argument. Typically I would use something like this:
sub foo {
($self, $optarg) = @_;
$optarg ||= 1;
}
I would like the optional argument to be treated as boolean, with the default being true
. This obviously won't work with the above, since $optarg
will evaluate to false if the argument is not passed in.
Is there a way to differentiate the absence of an argument being passed and a value that evaluates to false?