in reply to Setting defaults in subroutines

Further to davorg's explanation, my usual idiom for getting the desired result is to move the default into the dereference:

my @index = @{ $args{Index} || [] };

This sidesteps the problem of @array || something forcing the array into scalar context, and also permits an undefined value.

Hugo

Replies are listed 'Best First'.
Re^2: Setting defaults in subroutines
by hmerrill (Friar) on Aug 04, 2004 at 11:26 UTC
    I agree. The best way to clarify your test and sidestep the precedence issue is to use parenthesis to explicitly describe how your test should be evaluated.