From 66a642a2c4df038aec31967dabd0b53f6448d150 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 4 Jan 2011 22:12:56 -0500 Subject: [PATCH] playing with the smart match operator --- cli/operators.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cli/operators.pl b/cli/operators.pl index a955f40..7609012 100644 --- a/cli/operators.pl +++ b/cli/operators.pl @@ -1,6 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; +use 5.0100; sub println { @@ -132,3 +133,22 @@ print 1 .. 20, "\n"; print '&' .. '!', "\n"; print 10 .. -10, "\n"; print "$_\n" foreach 1 .. 10, "\n"; + + +my $scalar = 'hi'; +my @array = qw(one two three); +my %hash = ( + hi => 1, + ho => 2, + he => 3, +); + +if ($scalar ~~ @array) { + print "scalar matches array\n"; +} +if ($scalar ~~ %hash) { + print "scalar matches hash\n"; +} +if (@array ~~ %hash) { + print "array matches hash\n"; +}