playing with the smart match operator
This commit is contained in:
parent
5ec66997df
commit
66a642a2c4
@ -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";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user