in reply to bug? why does this ~~ smart match to an array slice fail?

No special behaviour is documented for array slices. An array slice in list context returns its last element, so you're matching against that. Array slices should probably behave like array refs, but it's not documented to do so.

Of course, you can do that yourself:

$i ~~ [ @ar[1..4] ]

Replies are listed 'Best First'.
Re^2: bug? why does this ~~ smart match to an array slice fail?
by flies (Novice) on Sep 30, 2010 at 19:26 UTC
    "An array slice in list context returns its last element"
    didn't know that. explains this behavior. not a bug.
Re^2: bug? why does this ~~ smart match to an array slice fail?
by andal (Hermit) on Oct 01, 2010 at 10:05 UTC
    I guess we are talking about array slices in scalar context. Only in scalar context the array slices return last element. And this is the biggest difference between array slices and arrays. The arrays return the number of elements. I guess in this situation, there's no bug. The ~~ operator works with arrays, not with lists, and array slice is the list. Unfortunately perl documentation does not cover the case of using list as the argument for smart match. But looking at the functionality it is clear, that operator works in scalar context with the objects that are passed to it. As result, the list of scalars always returns the last scalar.

      Unfortunately perl documentation does not cover the case of using list as the argument for smart match

      The smart match operator's operands are evaluated in scalar context. They can't possibly return a list. Furthermore, perlop and perlfunc are very clear as to what each operator returns in scalar context. There are a couple of exceptions:

      @array is special-cased to mean \@array
      %hash is special-cased to mean \%hash
      /pat/ is special-cased to mean qr/pat/