使用Python -我可以接受一个字符串并用多字节字符UTF-8转义返回它:
$ python3 -c 'print("hello ☺ world".encode("utf-8"))'
b'hello \xe2\x98\xba world'或者unicode逃脱了:
$ python3 -c 'print("hello ☺ world".encode("unicode-escape"))'
b'hello \\u263a world'Perl可以这样做吗?我试过“验证码”,但它似乎不是正确的工具:
$ perl -e 'print quotemeta("hello ☺ world\n");'
hello\ \�\�\�\ world\发布于 2018-11-08 15:45:31
例如,Data::Dumper可以做到这一点。
use utf8;
use Encode;
use Data::Dumper;
$Data::Dumper::Terse = 1; # suppress '$VAR1 = ...' header
$Data::Dumper::Useqq = 1; # make output printable
print Dumper("hello ☺ world");
print Dumper(encode("UTF-8","hello ☺ world"));输出:
"hello \x{263a} world"
"hello \342\230\272 world"更新:Data::Dumper模块中的相关函数是qquote,因此可以跳过设置$Useqq和$Terse
use utf8;
use Encode;
use Data::Dumper;
print Data::Dumper::qquote("hello ☺ world"), "\n";
print Data::Dumper::qquote(encode("UTF-8","hello ☺ world")), "\n";https://stackoverflow.com/questions/53210791
复制相似问题