〜在Perl中做什么

〜在Perl中做什么

本文介绍了=〜在Perl中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我猜该标签是一个变量,并且正在检查9eaf-但这在Perl中存在吗?

I guess the tag is a variable, and it is checking for 9eaf - but does this exist in Perl?

这里的"=〜"符号是什么?9eaf之前和之后的"/"字符是什么?

What is the "=~" sign doing here and what are the "/" characters before and after 9eaf doing?

if ($tag =~ /9eaf/)
{
    # Do something
}

推荐答案

=~是用于测试正则表达式匹配项的运算符.表达式/9eaf/是正则表达式(斜杠//是定界符,9eaf是实际的正则表达式).换句话说,测试将说如果变量$ tag与正则表达式/9eaf/...相匹配",并且在$tag中存储的字符串在任意点上连续连续包含那些字符9eaf时,就会发生此匹配.因此,对于字符串而言,这将是正确的

=~ is the operator testing a regular expression match. The expression /9eaf/ is a regular expression (the slashes // are delimiters, the 9eaf is the actual regular expression). In words, the test is saying "If the variable $tag matches the regular expression /9eaf/ ..." and this match occurs if the string stored in $tag contains those characters 9eaf consecutively, in order, at any point. So this will be true for the strings

9eaf

xyz9eaf

9eafxyz

xyz9eafxyz

还有很多其他的,但不是字符串

and many others, but not the strings

9eaxxx
9xexaxfx

和许多其他.在'perlre'手册页中查找有关正则表达式的更多信息,或查找Google"perl正则表达式" .

and many others. Look up the 'perlre' man page for more information on regular expressions, or google "perl regular expression".

这篇关于=〜在Perl中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 03:10