perl – 如何将’hash string’转换为hash?

前端之家收集整理的这篇文章主要介绍了perl – 如何将’hash string’转换为hash?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有存储在文件中的哈希字符串,{“a”=> 1,“b”=> 2},我打开文件并将此哈希字符串存储到$hash_string,如何将此$hash_string转换为$hash_string_ref = { “一个”=大于1中,“b”=大于2}?

解决方法

简单的答案:

$echo '{"a"=>1,"b"=>2}' > val.pl
$perl -le 'my $foo = do "val.pl"; print $foo->{a}'
1

更好的答案:考虑使用更好的数据序列化格式,例如StorableYAML,甚至是JSON.

猜你在找的Perl相关文章