简体   繁体   English

Perl转义英镑符号

[英]Perl escaping pound sign

I have a variable and am trying to pass in the following PW: 我有一个变量,正在尝试传递以下PW:

my $pass    = 'trAF\#\1cMax\$\';

Even though I'm escaping the # sign, its still thinking that the string ends with an F and causes an error as the code thinks its missing a semi-colon. 即使我转义了#号,它仍然认为字符串以F结尾并导致错误,因为代码认为其缺少分号。

Be interested in any thoughts. 对任何想法都感兴趣。

There's no problem with # . #没有问题。 The only problem is that you're accidentally escaping the closing delimiter. 唯一的问题是您不小心转义了结束定界符。

In single-quoted strings, you can only escape the delimiter and \\ because there's no need to escape anything else. 在单引号字符串中,您只能转义定界符和\\因为无需转义其他任何内容。 You can even avoid escaping \\ if it's unambiguous, but that's not the case for the second \\ . 你甚至可以逃脱避免\\如果它是明确的,但是这不是第二个的情况下\\

Both

my $pass = 'trAF#\\1cMax\\$\\';

and

my $pass = 'trAF#\1cMax\$\\';

assign the following string to $pass : 将以下字符串分配给$pass

trAF#\1cMax\$\

If you meant to obtain the string 如果您要获取字符串

trAF#1cMax$

then all you need is 那么你所需要的就是

my $pass = 'trAF#1cMax$';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM