通过智能匹配简化工作

#通过智能匹配,判断hash 或者数组是否存在键
if ($key ~~ %hash ) { .. }
if ($name ~~ @cats ) {.. }
use 5.014;
#用正则表达式检查散列键
if (%hash ~~ /$regex/) {
}
# 数组检查
if (@array ~~ /$regex/) {
}

其他通过智能匹配可以大大简化代码的操作有:

%hash1 ~~ %hash2   # 键相同的两个散列
@array1 ~~ @array2 #完全相同的两个数组
%hash ~~ @keys      #数组中是否存在%hash的某个键
$scalar ~~ $code_ref
原文地址:https://www.cnblogs.com/tjxwg/p/2955371.html