in reply to smartmatch and index

Index doesn't even make sense for most smart-match inputs, so it doesn't make sense for smart-matching in general.

This is probably what you want:

my @indexes = map { EXPR ~~ $a[$_] } 0..$#a;

Replies are listed 'Best First'.
Re^2: smartmatch and index
by Anonymous Monk on Oct 13, 2010 at 14:39 UTC
    hopefully we're not arguing semantics...but i think being able to get the index (array 'position') based on the result of a positive smartmatch is very useful. knowing that ( "foo" ~~ @big_array ) is true is helpful (and we rejoice in how fast it is). in some cases knowing that "foo" is at index 346456 may be really really helpful. i realize that "foo" could appear repeatedly and in that case the map example is a good solution. it would be nice if the smartmatch function could be a bit more "telling".

      i think being able to get the index (array 'position') based on the result of a positive smartmatch is very useful.

      Indeed, and I showed you how to do it.

      it would be nice if the smartmatch function could be a bit more "telling".

      Smart match has nothing to do with arrays. It can't return indexes when most match rules don't even involve indexes.