playing with the smart match operator

This commit is contained in:
Dan Buch 2011-01-04 22:12:56 -05:00
parent 5ec66997df
commit 66a642a2c4

View File

@ -1,6 +1,7 @@
#!/usr/bin/env perl #!/usr/bin/env perl
use strict; use strict;
use warnings; use warnings;
use 5.0100;
sub println { sub println {
@ -132,3 +133,22 @@ print 1 .. 20, "\n";
print '&' .. '!', "\n"; print '&' .. '!', "\n";
print 10 .. -10, "\n"; print 10 .. -10, "\n";
print "$_\n" foreach 1 .. 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";
}