Avis, Ed wrote: > >There are no array slices in your examples. In a [] subscript, > >expressions are evaluated in scalar context. > > Well, not in the case of > > @a[0, 1, 2] > > It is tempting for the programmer to try the same thing with a listref: > > $r->[0, 1, 2] > > although in fact the correct way to do it is > > @$r[0, 1, 2] > > A warning for the second case would be a good idea, since it's a little > counterintuitive that the square brackets behave differently in the two > cases.
Maybe, but such a warning can only be produced by dirty heuristics (like the C<print ("foo")> warning, and I'm slightly opposed to heuristic-driven warnings. Sometimes they are wrong, and sometimes they don't occur where they would have been useful. > perlop says: > > >If either operand of scalar ".." is a constant expression, that operand > >is considered true if it is equal ("==") to the current input line num- > >ber (the $. variable). > > So somehow it must be comparing 0 and 1 to $., which in this example > program is always undef since we haven't read a line from input. > > I'll remember to be careful when using .. for ranges in case I get the > wrong operator by accident. Right. So, no bug. (Although the incrementation of the return value of .. is not expected/documented, but a side-effect of the implementation). -- Fix in six / Fix in six / And we'll take over Unix