📜  珀尔 | quotemeta()函数

📅  最后修改于: 2022-05-13 01:55:14.943000             🧑  作者: Mango

珀尔 | quotemeta()函数

Perl 中的 quotemeta()函数转义作为参数传递给它的值中的所有元字符。

例子:

Input : "GF*..G" 
Output : "GF\*\.\.G"

示例 1:

#!/usr/bin/perl -w
$string = "GF*\n[.]*G";
  
print "Original String: \n";
print $string;
  
# Applying operation on the String
print "\n\nString after operation: \n";
print quotemeta($string);

输出:

Original String: 
GF*
[.]*G

String after operation: 
GF\*\
\[\.\]\*G


示例 2:

#!/usr/bin/perl -w
$string = "GF+n\{.}/G";
  
print "Original String: \n";
print $string;
  
# Applying operation on the String
print "\n\nString after operation: \n";
print quotemeta($string);

输出:

Original String: 
GF+n{.}/G

String after operation: 
GF\+n\{\.\}\/G