I am attempting to write a hash, which is written very slowly, into a data file, but am unsure about how Perl6 does this in comparison to Perl5. This is a similar question Storing intermediate data in a file in Perl 6 but I don't see how I can use anything written there, specifically messagepack.
I'd like to see the Perl6 equivalent of
my %hash = ( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4);
use Storable;
store \%hash, 'hash.pldata';
and then read with
my $hashref = retrieve('hash.pldata');
my %hash = %{ $hashref };
This is built in to Perl5, it's super easy, I don't need to install any modules (I love it!), but how can I do this in Perl6? I don't see it in the manual. They appear to be talking about something else with STORE
https://docs.perl6.org/routine/STORE
While these do not directly match Storable, there are a couple of approaches outlined at:
Another option for simple objects is to use .perl to 'store' then EVAL to 'read' ... from https://docs.perl6.org/routine/perl
How about this? OK, not as efficient as
Storable
but it seems to work....I get this
I seriously think you should move away from Storable and over to JSON. If you're using Rakudo Star as your install it includes a number of different JSON modules as part of it's core install so you don't need to add anything extra.
JSON is compatible with a number of different languages (not just Perl) and is a defined standard (unlike Storable which is backward incompatible). And JSON file sizes are of a similar size (if not smaller).
About the only plus point of Storable over JSON is handling code references. But if you're just storing data I wouldn't advise using Storable.