Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing intermediate data in a file in Perl 6

Tags:

raku

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?

like image 336
Eugene Barsky Avatar asked Oct 16 '18 07:10

Eugene Barsky


1 Answers

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

like image 143
timotimo Avatar answered Nov 06 '22 22:11

timotimo