Wow. I learn something new every day.
Just wanted to add my $0.02 on this:
1. perldoc perlop, search for and read the following
sections: "C-Style Logical Or" and "Range Operators"
(which are conveniently co-located...)
2. Quote from "C-Style Logical Or":
@a = @b || @c; # this is wrong
@a = scalar(@b) || @c; # really meant this
@a = @b ? @b : @c; # this works fine, though
So, the suggestion of using the ternary operator is a
good one. For large arrays, I usually use references,
though, if I know that I won't be modifying the array:
$a = int @b ? \@b : \@c;
(I use the 'int' operator there for readability. It's
superfluous, and does the same thing as the 'scalar'
operator for that particular example.
Also note that the only difference between the '||'
operator and the 'or' operator is precedence.
3. I don't think anyone specifically called it out, but
the '..' operator returns a boolean *whenever* it is
evaluated in scalar context, not just whenever there is
a constant in there. Having the constant in there
*also* compares that constant to the '$.' variable.
I just wanted to chip in that clarification. Sorry if
someone did point that out and I just missed it.