Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created December 12, 2010 10:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tadzik/737973 to your computer and use it in GitHub Desktop.
diff --git a/misc/perl6advent-2010/articles/smartmatching.pod b/misc/perl6advent-2010/articles/smartmatching.pod
index cda1b95..b3f8afd 100644
--- a/misc/perl6advent-2010/articles/smartmatching.pod
+++ b/misc/perl6advent-2010/articles/smartmatching.pod
@@ -41,11 +41,15 @@ C<m/.../> and C<.method_call>.
Here is what the smart match operator does with some matchers on the
right-hand side:
- matcher operation
- --------------------------
- type object type check
- Numeric numeric equality
- Str string equality
- Regex $_ matches regex?
- Range $_ is inside the range
- Code closure is called with $_ as argument
+ # is it of type Str?
+ $foo ~~ Str
+ # is it equal to 6?
+ $foo ~~ 6
+ # or is it "bar"?
+ $foo ~~ "bar"
+ # does it match some pattern?
+ $foo ~~ / \w+ '-' \d+ / # TODO: notice how that's the only way now, no =~ in Perl6
+ # Is it between 15 and 25?
+ $foo ~~ (15..25)
+ # call a closure
+ $foo ~~ -> $x { say 'ok' if 5 < $x < 25 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment