0

我需要使用 Perl (v5.10) 处理来自另一个应用程序的字符串,其中嵌入了空格、逗号和其他非字母数字字符的八进制值。

例如:这个 - “11624\0040SE\00405th\0040St\0054\0040Suite\0040100”,应该是这个 - “11624 SE 5th St, Suite 100”。

我可以用“echo -e”完成我在 Linux 命令行中寻找的东西,但我需要能够在 Perl 脚本中进行处理和操作。

axiar@formdev$echo -e "11624\0040SE\00405th\0040St\0054\0040Suite\0040100"

11624 SE 5th St,套房 100

我查看了 String::Escape 模块,但它似乎没有做我认为应该做的事情。

use String::Escape qw(backslash unbackslash);
my $strval="11624\0040SE\00405th\0040St\0054\0040Suite\0040100";
my $output=unbackslash($strval);
printf("%s\n",$strval);
printf("%s\n",$output);

我已经在 Google 和 Stack Overflow 上搜索了很多类似的问题/答案,但还没有遇到任何问题。

您的专家协助将不胜感激。

4

1 回答 1

0

这种类型的事情通常很容易在正则表达式中完成:

$ perl -E 'say shift =~ s[\\0([0-7]{1,3})][chr oct $1]egr' '11624\0040SE\00405th\0040St\0054\0040Suite\0040100' 11624 SE 5th St, Suite 100

这样可能更容易。

于 2017-05-31T20:43:33.297 回答