问题描述
有对Perl的数据序列化这么多的模块,我不知道该选哪一个。
There are so many modules for serializing data for Perl, and I don't know which one to choose.
我有以下数据,我需要序列化作为一个字符串,所以我可以把它放在数据库:
I've the following data that I need to serialize as a string so I can put it in the database:
my @categories = (
["Education", "Higher Education", "Colleges"],
["Schooling", "Colleges"]
);
我怎么可能把它变成文字,再后来,当我需要的时候,回头到数组引用数组?
How could I turn it into text, and then later when I need it, turn back into an array of array-references?
推荐答案
我投了JSON(或数据::串行
作为另一个答案与所提到的,结合 JSON
)。
I vote for JSON (or Data::Serializer
as mentioned in another answer, in conjunction with JSON
).
的 JSON
模块是大量快速,高效的(如果你从CPAN安装JSON :: XS,它会编译C版本供您和使用JSON
将自动使用)。
The JSON
module is plenty fast and efficient (if you install JSON::XS from cpan, it will compile the C version for you, and use JSON
will automatically use that).
这与Perl数据结构的伟大工程,是标准化的,而JavaScript语法是如此的相似,Perl的语法。还有,你可以用 JSON
模块设置选项来提高人类的可读性(换行等)
It works great with Perl data structures, is standardized, and the Javascript syntax is so similar to Perl syntax. There are options you can set with the JSON
module to improve human readability (linebreaks, etc.)
我也用可存储
。我不喜欢它 - 该接口是怪异,输出是荒谬的,它是一个专有格式。 数据::自卸车
快速且相当可读的,但真正的意思是单向的(评估
ING是稍微hackish的),并再次,它只是Perl的。我还推出我自己也是如此。最后,我总结JSON是最好的,是快速,灵活和可靠的。
I've also used Storable
. I don't like it--the interface is weird, and the output is nonsensical, and it is a proprietary format. Data::Dumper
is fast and quite readable but is really meant to be one-way (eval
ing it is slightly hackish), and again, it's Perl only. I've also rolled my own as well. In the end, I concluded JSON is the best, is fast, flexible, and robust.
这篇关于如何序列在Perl数组引用数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!