in reply to Re: Optional and default parameters for a subroutine
in thread Optional and default parameters for a subroutine

But as you noted, that will only work if your arguments are always true, or that false indicates "default value". The nice thing about using the %hash = ( default => "value", @_ ); construct (besides being shorter) is that it works for all values.

To do the same with explicit testing you'd need

$args{arg1} = 'default value1' unless exists $args{arg1};

Replies are listed 'Best First'.
Re^3: Optional and default parameters for a subroutine
by saberworks (Curate) on Aug 29, 2005 at 20:34 UTC
    Although I wrote the phrase, "if it evaluates to true," I didn't consider its implications. Thanks for pointing that out.