Perl 6 Perl 6 #21

Smart matching

Perl 5's =~ operator becomes ~~ ("smart match") in Perl 6

$x ~~ /^ 'msg' \d+ '.txt' $/   # normal regex match

But it can also be used with other types

$spot ~~ Dog                   # $spot isa Dog

@a ~~ @b                       # array equality

@a ~~ / foo /                  # elements of @a matching 'foo'

$y ~~ $n..$m                   # range match $n <= $y <= $m
Copyright © 2008 Patrick Michaud