in reply to Best method of assigning "default" values?
I'm going to broaden the topic to positional arguments for future reference. For positional arugments, the equivalent of exists that davidrw suggested for hashes would be to check the size of @_.
sub my_sub { my ($arg1, $arg2, $opt_arg1, $opt_arg2) = @_; $opt_arg1 = default if @_ < 3; $opt_arg2 = default if @_ < 4; ... }
That allows all false values to be specified, including undef.
|
|---|