智能匹配操作符:~~
use 5.010001;
say "I found Fred in the same" if $name ~~ /Fred/;
找出哈希表中是否包含“Fred”
use 5.010001;
say "I found a key matching 'Fred'" if %name ~~ /Fred/;
use 5.010001;
my @nums = qw(1 2 3 27 42);
my $result = max(@nums);
say "The result [$result] is one of the input values()@nums" if $result ~~@nums;
given语句:像c语言中的switch语句
given($ARGV[0])
{
when ($_ ~~ 'Fred') { }
when ($_ ~~ /Fred/i) { }
when ($_ ~~ /\Afred/)
default { }
}
笨拙匹配:
~~加正则表达式
Perl语言入门笔记 第十五章 智能匹配与given-when结构
于 2015-09-21 02:06:16 首次发布