我是 perl 的初学者,我有一个关于模式匹配的查询。
我在 perl 中遇到了一行写在那里
$variable =~ s-/\Z--;
随着代码的进行,一些另一个变量被分配
$variable1 =~ s-/--;
你能告诉我这两行是做什么的吗?
我想知道是什么
s-/\Z--
和 s-/--
意思。
最佳答案
$variable =~ s-/\Z--;
-
在这里用作分隔符。但是,最佳实践建议您使用 /
或 {}
作为分隔符。可以改写为:
$variable =~ s{/\Z}{}; # remove a / at the end of a string
考虑:
$variable1 =~ s-/--;
同样,它可以重写为:
$variable1 =~ s{/}{}; # remove the first /
关于regex - perl 中的 s-/-- 和 s-/\Z-- 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6556904/