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.
But of course, you *do* get a warning usually: perl -we '$a->[3,4,5]' Useless use of a constant in void context at -e line 1. Useless use of a constant in void context at -e line 1. Useless use of array element in void context at -e line 1. Name "main::a" used only once: possible typo at -e line 1. You're just unlucky that you've chosen the particular range 0..1, since these two constants are exempted from the "Useless use" message. Mike Guy