From perlop
Binary ".." is the range operator, which is really two different operators depending on the context. In list context, it returns a list of values counting (up by ones) from the left value to the right value. If the left value is greater than the right value then it returns the empty list.
(emphasis added). So:
@a = (1
@b = (3
@c = reverse (1
Why is this? I had occasion to do this the other day, and my first cut at the code did the equivalent of @b above, instead of @c, which led to a few moments headscratching.
It struck me as odd that Perl, which so often DWIMs, gets it wrong here.
DWIM depends (Score:1)
$x, and x might be zero or less (in which case I would want an empty list), then I'd rather not have to sayif ($x >= 1) ..., I can just say(1..$x). I think it was felt that that was the more common case than wanting the reverse list.Re: (Score:1)
Indeed. The current behaviour is sometimes annoying, but never surprising. The alternative would be sometimes convenient, but often surprising.
Re: (Score:1)