问题描述
在 perl 中假设我有一个像 'helloworld'
这样的字符串,我想要的是:
In perl suppose I have a string like 'helloworld'
, and what I want is:
'hello world
'
也就是说,hello",然后是文字制表符,然后是world",然后是文字换行符.或者等效地,"helloworld"
(注意双引号).
That is, "hello", then a literal tab character, then "world", then a literal newline. Or equivalently, "helloworld"
(note the double quotes).
换句话说,是否有一个函数可以获取带有转义序列的字符串并返回一个插入了所有转义序列的等效字符串?我不想插入变量或其他任何东西,只是像 x
这样的转义序列,其中 x
是一个字母.
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 world
');
这篇关于如何在 Perl 字符串中手动插入字符串转义符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!