在 Perl 6 中的文件中存储中间数据 [英] Storing intermediate data in a file in Perl 6
问题描述
我的一些程序由两部分组成.首先,他们从文件中读取大数据并对其进行转换,生成Array
s、Hash
es、Object
s 等;其次,他们使用(总是不同的)用户定义的条件来分析这些数据.第一部分保持不变(只要源数据没有改变),但有时每次运行程序都需要相当长的时间,而且我通常必须使用相同的源数据多次运行它.拥有两个程序会好得多——其中一个(一次)读取数据并对其进行转换,而另一个对其进行分析(多次).
Some of my programs consist of two parts. First, they read large data from files and transform it, producing Array
s, Hash
es, Object
s etc.; second, they analyse this data with (always different) user-defined conditions. The first part remains the same (as long as the source data isn't changed), but sometimes it takes considerable time to work every time I run the program, and I usually have to run it many times with the same source data. It would be much better to have two programs — one of them (once) reads the data and transforms it, while the other analyses it (many times).
我的问题是:存储那些 Array
s、Hash
es 和 Object
s 的最佳方法是什么,以便第一个程序写入将它们写入一个文件,第二个从该文件读取它们?
My question is: what's the best way to store those Array
s, Hash
es and Object
s, so that the first program writes them to a file and the second one reads them from that file?
推荐答案
您可以将数据结构写入 Perl 6 源文件并使用"它,然后它会为您预编译,这可能是将数据结构导入 Perl 6 程序的最快方法.
You can write the data structure to a Perl 6 source file and "use" it, then it'll be pre-compiled for you, which is potentially the fastest way to get a data structure into a Perl 6 program.
除此之外,JSON 有一些显着的限制,而原生 Perl 6 数据结构没有,例如整数和浮点数之间的区别,以及对 Inf、-Inf 和 NaN 的支持.也不支持复杂"对象中的键,即没有数组作为哈希键.
Other than that, JSON has some notable limitations that native Perl 6 data structures don't have, like the difference between integers and floating point numbers, and support for Inf, -Inf and NaN. There's also no support for keys in objects that are "complex", i.e. no arrays as hash keys.
MessagePack 是一个示例序列化格式,它支持 Perl 6 所能提供的大部分内容.已经有模块了,到目前为止我只使用过 Data::MessagePack,但这里是列表:https://modules.perl6.org/search/?q=messagepack
One example serialization format that supports most of what Perl 6 can throw at it is MessagePack. There's modules for it already, I have only used Data::MessagePack so far, but here's the list: https://modules.perl6.org/search/?q=messagepack
这篇关于在 Perl 6 中的文件中存储中间数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!