如何在Perl字符串中手动插入字符串转义? [英] How can I manually interpolate string escapes in a Perl string?
问题描述
'hello\tworld\\\
'
,我想要的是: 'hello world
'
那就是你好,然后是一个文字标签字符,然后是世界,然后是一个字面的换行符。或者等价地,hello\tworld\\\
(注意双引号)。换句话说,是否有一个函数来获取一个带有转义序列的字符串,并返回一个等价的字符串,并插入所有的转义序列?我不想内插变量或其他任何东西,只是转义序列,如 \x
,其中 x
是一个
听起来像一个问题,别人会有已解决。我从来没有使用这个模块,但它看起来很有用:
使用String :: Escape qw(unbackslash);
my $ s = unbackslash('hello\tworld\\\
');
In perl suppose I have a string like 'hello\tworld\n'
, and what I want is:
'hello world
'
That is, "hello", then a literal tab character, then "world", then a literal newline. Or equivalently, "hello\tworld\n"
(note the double quotes).
In other words, is there a function for taking a string with escape sequences and returning an equivalent string with all the escape sequences interpolated? I don't want to interpolate variables or anything else, just escape sequences like \x
, where x
is a letter.
Sounds like a problem that someone else would have solved already. I've never used the module, but it looks useful:
use String::Escape qw(unbackslash);
my $s = unbackslash('hello\tworld\n');
这篇关于如何在Perl字符串中手动插入字符串转义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!