【文件属性】:
文件名称:Perl的模式匹配-Perl training ppt
文件大小:1.16MB
文件格式:PPT
更新时间:2021-04-25 09:01:37
Perl Training
Perl的模式匹配
1 模式匹配操作符 =~、!~
=~检验匹配是否成功,!~则相反,如
$result = ($var =~ /abc/);
若在该字符串中找到了该模式,则返回非零值,即true,不匹配则返回0,即false。
2 替换操作符,语法为 s/pattern/replacement/
$string = "abc123def";
$string =~ s/123/456/; # now $string = "abc456def";
3 翻译操作符,语法为 tr/string1/string2/
$string = "abcdefghicba";
$string =~ tr/abc/def/; # now string = "defdefghifed"