m! 是什么意思?在这个 perl 语法中意味着
What does the m! in this perl syntax mean
在尝试调试我在使用 git-svn 和 --ignore-paths 选项时遇到的问题时,我 运行 进入了这个我不理解的 perl 表达式并且在 perl 文档中找不到类似的内容。
$path =~ m!$self->{ignore_regex}!
我对此的理解是,这是将 $path 字符串与 ignore_regex 匹配,但它似乎与我期望的方式不匹配。我不明白的部分是 $self->{ignore_regex}
?
周围的 m! !
我应该如何阅读这个语法?
m!...!
更常写成 /.../
,但它们 100% 相同。
If "/"
is the delimiter then the initial m
is optional. With the m
you can use any pair of non-whitespace (ASCII) characters as delimiters. This is particularly useful for matching path names that contain "/"
, to avoid LTS (leaning toothpick syndrome). [...]
例如,以下是相同的:
$path =~ /$self->{ignore_regex}/
$path =~ m/$self->{ignore_regex}/
$path =~ m^$self->{ignore_regex}^
$path =~ m{$self->{ignore_regex}}
有问题的代码检查 $path
中的字符串是否与 $self->{ignore_regex}
中的正则表达式匹配。
在尝试调试我在使用 git-svn 和 --ignore-paths 选项时遇到的问题时,我 运行 进入了这个我不理解的 perl 表达式并且在 perl 文档中找不到类似的内容。
$path =~ m!$self->{ignore_regex}!
我对此的理解是,这是将 $path 字符串与 ignore_regex 匹配,但它似乎与我期望的方式不匹配。我不明白的部分是 $self->{ignore_regex}
?
m! !
我应该如何阅读这个语法?
m!...!
更常写成 /.../
,但它们 100% 相同。
If
"/"
is the delimiter then the initialm
is optional. With them
you can use any pair of non-whitespace (ASCII) characters as delimiters. This is particularly useful for matching path names that contain"/"
, to avoid LTS (leaning toothpick syndrome). [...]
例如,以下是相同的:
$path =~ /$self->{ignore_regex}/
$path =~ m/$self->{ignore_regex}/
$path =~ m^$self->{ignore_regex}^
$path =~ m{$self->{ignore_regex}}
有问题的代码检查 $path
中的字符串是否与 $self->{ignore_regex}
中的正则表达式匹配。