如何在 Perl 字符串中手动插入字符串转义符? [英] How can I manually interpolate string escapes in a Perl string?

查看:33
本文介绍了如何在 Perl 字符串中手动插入字符串转义符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 perl 中假设我有一个像 'hello world ' 这样的字符串,我想要的是:

In perl suppose I have a string like 'hello world ', and what I want is:

'hello  world
'

也就是说,hello",然后是文字制表符,然后是world",然后是文字换行符.或者等效地,"hello world "(注意双引号).

That is, "hello", then a literal tab character, then "world", then a literal newline. Or equivalently, "hello world " (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 字符串中手动插入字符串转义符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆