```{index} single: PDL::IO::Storable ``` # PDL::IO::Storable helper functions to make PDL usable with serialisation packages ## SYNOPSIS ```perl use Storable; use PDL::IO::Storable; $hash = { 'foo' => 42, 'bar' => zeroes(23,45), }; store $hash, 'perlhash.dat'; use JSON::MaybeXS; $encoder = JSON::MaybeXS->new(allow_tags => 1); my $ndarray = xvals (5,2); my $encoded_json = $encoder->encode ($ndarray); my $decoded_ndarray = $encoder->decode ($encoded_json); ``` ## DESCRIPTION Serialisation packages such as `Storable`, `Sereal`, `JSON::MaybeXS` and `CBOR::XS` implement object persistence for Perl data structures that can contain arbitrary Perl objects. This module implements the relevant methods to be able to store and retrieve ndarrays via `Storable` as well as packages that support the [Types::Serialiser](https://metacpan.org/pod/Types::Serialiser) protocol (currently [Sereal](https://metacpan.org/pod/Sereal), [CBOR::XS](https://metacpan.org/pod/CBOR::XS) and JSON packages). Note that packages supporting the `Types::Serialiser` protocol need to have their respective flags enabled so that the FREEZE and THAW callbacks are used. Note also that while [JSON::MaybeXS](https://metacpan.org/pod/JSON::MaybeXS) is supported, if it has to fall back to [JSON::PP](../../JSON/PP.md), it will fail. [JSON::XS](https://metacpan.org/pod/JSON::XS) treats the data it gets back from `FREEZE` as items to encode, while [JSON::PP](../../JSON/PP.md) treats the list it gets as strings already encoded. They are fundamentally incompatible, so this module supports the JSON::XS option. Finally, [data flow](https://metacpan.org/pod/PDL::Dataflow) is not preserved. If a data structure containing ndarrays connected by data flow is serialised then this will need to be explicitly reinstated on deserialisation. ## FUNCTIONS ### store store an ndarray using [Storable](../../Storable.md) ```perl $x = random 12,10; $x->store('myfile'); ``` ### freeze freeze an ndarray using [Storable](../../Storable.md) ```perl $x = random 12,10; $frozen = $x->freeze; ``` ## AUTHOR Copyright (C) 2013 Dima Kogan Copyright (C) 2002 Christian Soeller All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file.