- 求职 : 软件工程师
- 论坛徽章:
- 3
|
本帖最后由 104359176 于 2015-12-16 10:57 编辑
- use 5.020;
- use experimental qw(switch autoderef);
- if (['a'] ~~ [['a'],['b']]) {
- say 'yes';
- } else {
- say 'not';
- }
- # output: not
- if (('a') ~~ (['a'],['b'])) {
- say 'yes';
- } else {
- say 'not';
- }
- # output: not
- if ('a' ~~ ('a','b')) {
- say 'yes';
- } else {
- say 'not';
- }
- # output: not
- if ('a' ~~ ['a','b']) {
- say 'yes';
- } else {
- say 'not';
- }
- # output: yes
复制代码 Perl5 的智能匹配操作符在用作探测是否在一个数组中有一个元素的时候,行为并不是正交的,也就是说,只能在 <字符串> ~~ <字符串一维数组> 情况下通过。
不能匹配嵌套的数据结构,这和其他语言不同。 |
|