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

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.
  • Comment on Re^2: bug? why does this ~~ smart match to an array slice fail?

Replies are listed 'Best First'.
Re^3: bug? why does this ~~ smart match to an array slice fail?
by ikegami (Patriarch) on Oct 01, 2010 at 16:29 UTC

    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/