Storing intermediate data in a file in Perl 6

2019-06-16 12:49发布

Some of my programs consist of two parts. First, they read large data from files and transform it, producing Arrays, Hashes, Objects 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).

My question is: what's the best way to store those Arrays, Hashes and Objects, so that the first program writes them to a file and the second one reads them from that file?

标签: perl6
1条回答
SAY GOODBYE
2楼-- · 2019-06-16 13:46

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.

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.

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

查看更多
登录 后发表回答