Smartmatching
- Smartmatching is key to a number of Perl 6's features
- You can explicitly request a smartmatch with the
~~
operator
- Smartmatch tries to do the right thing:
-
$a ~~ m/\S+/
-- run the regex on $a
, returns Match
-
$a ~~ Int
-- returns True if $a is an Int
-
$a ~~ 34
-- returns True if $a == 34
-
$a ~~ { $_.Str ne $_.perl }
-- returns result of calling closure with argument $a
-
$a ~~ 2..5
-- returns True if $a is between 2 and 5, inclusive
- Syntactic sugar for (last example) (2..5).ACCEPTS($a)
« first
< prev
(23 / 41)
next >
last »