quotemeta EXPR quotemeta

Returns the value of EXPR with all non-"word" characters backslashed. (That is, all characters not matching "/[A-Za-z_0-9]/" will be preceded by a backslash in the returned string, regardless of any locale settings.) This is the internal function implementing the "\Q" escape in double-quoted strings.

If EXPR is omitted, uses $_.


my $s = "aab";
my $r = "a.b";
my $r2 = quotemeta $r;
print "ok" if $s =~ /$r/;   # will output "ok"
print "ok2" if $s =~ /$r2/; # won't output "ok2", because $r2 value is "a\.b"


这篇文章: 有用 无用
创建 2012-02-22 10:08:59 / 更新 2018-04-20 04:49:17