Perl字符串替换?

mys*_*boy -4 regex perl json replace

我有我的字符串如下,我想删除第一个{没有任何东西只有第一个是字符串的开头.字符串在替换之前打印正常但在替换其空字符串之后.

use strict;
use warnings;

my $string = {"something":[{"some":"12","some":"something","data":"","data":"data2","age":"23"},{......},{.....}]}

# the string is valid as it is json from some array function.

print $string."\n";   #My string prints fine here
 $string = s/\{//;

print "String after replacement".".$string." testing";
Run Code Online (Sandbox Code Playgroud)

And*_*ter 5

我强烈建议您使用现有的,经过测试的调试JSON模块来读取JSON,修改数据结构并将其写回来,而不是试图手动使用JSON.

请参阅JSON以获取将为您执行此操作的一个模块.

  • 还有https://metacpan.org/module/JSON::XS,我猜它比`JSON更快 (2认同)