perl智能匹配
1.perl中~~为智能匹配,它能够智能地依据符号两側的操作数来确定操作。
如要推断某个元素是否存在于数组中,不使用智能匹配,程序像这样:
my $x=2;
my @array=(1,2,3);
my $flag=0;
for (@array)
{
if($x==$_)
{
$flag=1;
}
}
if($flag == 1){
print "$x is in the array";
}
else
{
print "$x is not in the array";
}
使用智能匹配,程序像这样:
my $x=2;
my @array;
if(@array~~$x)
{
print "$x is in the array";
}
else
{
print "$x is in the array";
}
再如查看哈希表中是否存在某个键值
‘hello’~~{hello=>1,world=>2} 结果为true
2.智能匹配的优先级在perl的在线文档中,智能匹配会依照表格的顺序选择匹配,优先级从上到下逐渐减少。
$a $b Type of Match Implied Matching Cod
====== ===== ===================== =============
Hash Hash hash keys identical [sort keys %$a]~~[sort keys %$b]
Hash Array hash slice existence grep {exists $a->{$_}} @$b
Hash Regex hash key grep grep /$b/, keys %$a
Hash Any hash entry existence exists $a->{$b} Array Array arrays are identical[*]
Array Regex array grep grep /$b/, @$a
Array Num array contains number grep $_ == $b, @$a
Array Any array contains string grep $_ eq $b, @$a Any undef undefined !defined $a
Any Regex pattern match $a =~ /$b/
Code() Code() results are equal $a->() eq $b->()
Any Code() simple closure truth $b->() # ignoring $a
Num numish[!] numeric equality $a == $b
Any Str string equality $a eq $b
Any Num numeric equality $a == $b Any Any string equality $a eq $b
perl智能匹配的更多相关文章
- Perl语言学习笔记 15 智能匹配与give-when结构
1.智能匹配操作符 替代绑定操作符: 在哈希中查找某一个键: 比較两个数组是否全然同样: 查找列表中是否存在某个元素: 智能匹配操作符与顺序无关.~~ 左右元素能够互换 2.智能操作符优先级 3.gi ...
- perl 跨行匹配;
<pre name="code" class="html"><pre name="code" class="ht ...
- android音乐播放器开发 SweetMusicPlayer 智能匹配本地歌词
上一篇写了使用MediaPlayer播放音乐,http://blog.csdn.net/huweigoodboy/article/details/39861539. 代码地址:https://gith ...
- fastjson简单使用demo,@JSONField注解属性字段上与set、get方法上。实体类toString(),实体类转json的区别;_下划线-减号大小写智能匹配
一.demo代码 @JSONField注解属性字段上与set.get方法上.使用@Data注解(lombok插件安装最下方),对属性“笔名”[pseudonym]手动重写setter/getter方法 ...
- Perl 正则匹配经验记录
0.正则匹配字典:http://www.cnblogs.com/itech/archive/2010/03/19/1689793.html 1.$/=">";重新定义字符串分 ...
- perl 如何匹配ASCII码以及ASCII码转换
匹配ASCII码: /[:ascii:]/ ASCII码转换为数字: ord() 数字转换为ASCII码: chr()
- perl 正则匹配多个
Vsftp:/root# cat k1.pl my $_='upDaTe'; if( $_ =~ /^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK| ...
- perl 贪婪匹配小例子
redis01:/root# cat x2.pl my $str="a19823a456123"; if ($str =~/a(.*)23/){print "1----& ...
- 学生&部门智能匹配程序
Github链接 结对成员: 031502308 付逸豪 031502113 胡俊钦 数据生成 样例链接: 来点我啊 由于在生成数据的时候做了很多符合实际情况的限制,所以生成的数据都挺好的,就随便选了 ...
随机推荐
- PS 如何制作Vista的毛玻璃效果
1 对一个图像的任意一部分新建一个选区 2 对选中区域进行高斯模糊,大小为5像素 3 再次新建一个图层,填充为深蓝色(#E9E7E3),填充为10%-15%.高斯模糊0.5像素. 4 再对 ...
- lodash 移除假值数组 compact
创建一个移除了所有假值的数组.例如:false.null. 0."".undefined, 以及NaN 都是 “假值”. <!DOCTYPE html> <htm ...
- Android Studio加入插件(Genymotion)
官方模拟器的龟速已让我们无力吐槽.幸好有genymotion这款逆天的Android虚拟机,它有着高速的开启速度,良好的交互界面. 是Android开发必备的良品.甚至有些玩家已经用genymotio ...
- iOS将数组中的内容分拼接成字符串
NSString *string = [array componentsJoinedByString:@","];--分隔符
- win10 microsoft edge 浏览器收藏夹位置
1.打开文件夹,找到(注意 用户名 改为你自己的用户名) C:\Users\用户名\AppData\Local\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bb ...
- 工作总结 npoi 模板 导出公式 excel
Apache POI(5):公式(formula) Apache POI(5):公式(formula) 2016年08月01日 17:44:49 阅读数:1145 package com.hthk ...
- 工作总结 返回 json 后台对象中,某一个字段设为string 整个对象转换为json 返回到页面中
JsonRequestBehavior.AllowGet作用 若要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet MVC 默认 Request 方式为 Po ...
- .NET CORE 2.0小白笔记(五):配置的热更新、配置的框架设计
配置的热更新 什么是热更新:一般来说,我们创建的项目都无法做到热更新:即项目无需重启,修改配置文件后读取到的信息就是修改配置之后的 我们只需要吧项目中用到的IOptions改成IOptionsSnap ...
- Quartz.Net - Lesson 1: 使用Quartz
Lesson 1: 使用Quartz 本系列文章是官方3.x文档的翻译,原文地址:https://www.quartz-scheduler.net/documentation/quartz-3.x/t ...
- dedecms单独调用指定文章
{dede:arclist idlist='指定ID' limit='0,1'} <a href="[field:arcurl/]">[field:title/]< ...